#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool compare (int a, int b)
{
return a>b;
}
int main()
{
int arr[5]= {1,2,5,9,6};
sort (arr,arr+5, compare);
for (auto i: arr)
cout << i << " ";
return 0;
}
The above code is sorted in descending order. I am completely blank on how it is working. I read articles but did not get a good explanation.
- Why compare is not followed by () while calling as we do with functions?
- How does the compare function get the value as we do not have passed any parameters?
- How do return true and false results in descending order sorting?