for example the code bellow sort the vec on desc order :
std::vector<int> vec = {1, 2, 5, 4, 3};
sort(vec.rbegin(), vec.rend());
for(const auto v : vec)
std::cout << v << "\n";
output 5 4 3 2 1
On the C++ reference:
Sorts the elements in the range [first,last) into ascending order. The elements are compared using operator< for the first version [...]
The function call indeed sorts the vector in the ascending order starting form the last element up to the first element because there are used reverse iterators
When you are using reverse iterators then the vector is traversed in the reverse order.
Consider this for loop
Its output is
If you want to sort the vector in the ascending order in the direct direction then do not use the reverse iterators. For example
Or if to use the reverse iterators then instead of the default function object of the type
std::less<int>you need to use a function object of the typestd::greater<int>