Sorted 0 1 2 3 4 5 6 7 8 9
How to sort in descending order?
sort() takes a third parameter that is used to specify the order in which elements are to be sorted. We can pass “greater()” function to sort in descending order. This function does comparison in a way that puts greater element before.
Sorted 9 8 7 6 5 4 3 2 1 0
How to sort in particular order?
We can also write our own comparator function and pass it as a third parameter.
Intervals sorted by start time : [1, 9] [2, 4] [4, 7] [6, 8]
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sorting 2D Vector in C++ | Set 2 (In descending order by row and column)
- Sorting 2D Vector in C++ | Set 1 (By row and column)
- Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)
- Sorting Vector of Pairs in C++ | Set 2 (Sort in descending order by first and second)
- Sorting 2D Vector in C++ | Set 3 (By number of columns)
- Sorting of Vector of Tuple in C++ (Ascending Order)
- Sorting of Vector of Tuple in C++ (Descending Order)
- Keep track of previous indexes after sorting a vector in C++ STL
- Sorting Vector of Arrays in C++
- vector::front() and vector::back() in C++ STL
- vector::empty() and vector::size() in C++ STL
- vector::push_back() and vector::pop_back() in C++ STL
- vector::operator= and vector::operator[ ] in C++ STL
- vector::at() and vector::swap() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector::begin() and vector::end() in C++ STL
- vector :: cbegin() and vector :: cend() in C++ STL
- How to flatten a Vector of Vectors or 2D Vector in C++
- Structure Sorting (By Multiple Rules) in C++
- Sorting Array Elements By Frequency | Set 3 (Using STL)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.