GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

sort in cpp using third parameter as greater<int>()

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};
    int n = sizeof(arr)/sizeof(arr[0]);
 
    sort(arr, arr+n, greater<int>());
 
    cout << "Array after sorting : \n";
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
 
    return 0;
}

Output:

Array after sorting : 
9 8 7 6 5 4 3 2 1 0 

What exactly is greater<int>()  ? 

asked Feb 26 by anonymous

1 Answer

It is simply working as a compare function which is sorting in descending order
answered Feb 27 by sahil_coder
...