reverse sort function in c++ code example
Example 1: sort in descending order c++ stl
sort(arr, arr + n, greater<int>())
Example 2: how to sort in descending order in c++
sort(str.begin(), str.end(), greater<int>());
cout<<str;
Example 3: array sort c++
#include <iostream>
2 #include <array>
3 #include <string>
4 #include <algorithm>
5
6 using namespace std;
7
8 int main(){
9 array<string, 4> colours = {"blue", "black", "red", "green"};
10 for (string colour : colours){
11 cout << colour << ' ';
12 }
13 cout << endl;
14 sort(colours.begin(), colours.end());
15 for (string colour : colours){
16 cout << colour << ' ';
17 }
18 return 0;
19 }
66
20
21