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}
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);
1 int arr[]= {2,3,5,6,1,2,3,6,10,100,200,0,-10};
2 int n = sizeof(arr)/sizeof(int);
3 sort(arr,arr+n);
4
5 for(int i: arr)
6 {
7 cout << i << " ";
8 }
9
1// C++ program to sort a vector in non-decreasing
2// order.
3#include <bits/stdc++.h> // Vector
4#include <algorithm> // Sort
5using namespace std;
6
7int main()
8{
9// Initalizing the vector v with these values
10 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
11// Vector is sorted in ascending order
12 sort(v.begin(), v.end());
13
14 return 0;
15}