STL algorithms
The std::sort(first, last)
method takes the first
and last
iterator and sorts the elements within the range [first, last)
.
It works as long as the type of the compared elements has the <
operator defined, which is predefined for types like int
and std::string
.
std::sort is sufficient for most use cases, only use your own sort function if you know you need it.
Write a program which receives multiple integers, sorts them, and then prints them out.
std::vector<int>
variable.std::cin
inside a while loop condition to take the input integers.std::sort(v.begin(), v.end())
.