1#include <iostream>
2#include <vector>
3#include <algorithm>
4using namespace std;
5int main() {
6 vector<int> v = { 10, 9, 8, 6, 7, 2, 5, 1 };
7 sort(v.begin(), v.end(), greater <>());
8}
1int arr[10];
2int length = sizeof(arr)/sizeof(arr[0]);
3sort(arr, arr+length, greater<int>());
1int main()
2{
3 // Get the vector
4 vector<int> a = { 1, 45, 54, 71, 76, 12 };
5
6 // Print the vector
7 cout << "Vector: ";
8 for (int i = 0; i < a.size(); i++)
9 cout << a[i] << " ";
10 cout << endl;
11
12 // Sort the vector in descending order
13 sort(a.begin(), a.end(), greater<int>());
14
15 // Print the reversed vector
16 cout << "Sorted Vector in descendiing order:n";
17 for (int i = 0; i < a.size(); i++)
18 cout << a[i] << " ";
19 cout << endl;
20
21 return 0;
22}
1struct data{
2 string word;
3 int number;
4};
5
6
7bool my_cmp(const data& a, const data& b)
8{
9 // smallest comes first
10 return a.number < b.number;
11}
12
13std::sort(A.begin(), A.end(), my_cmp);