A
vector in C++
can be easily sorted in ascending order using the
sort()
function defined in the
algorithm
header file.
The
sort()
function sorts a given data structure and does not return anything. The sorting takes place between the two passed iterators or positions. The third parameter determines the
order
in which the elements are going to be compared.
By default, for not passing the third parameter, the function considers it to be the
std::less<int>()
function. This function returns
true
or
false
on the basis of comparing two arguments, whether the first one is less than the other.
So, now let us see how we can sort a vector in C++(ascending order).