I received an error while trying to run the following code, why is this happening? Do the sort function have any additional requirements for the comparison function
run the code
#include<algorithm>
using namespace std;
bool cmp(int i,int j){
return i<=j;
}
int main(){
int n=42;
int arr[]={36,0,21,52,13,24,47,88,83,19,36,50,85,37,6,85,43,18,11,100,78,43,0,43,18,99,38,62,56,82,16,81,22,75,33,80,34,57,30,5,58,91};
sort(arr,arr+n,cmp);
return 0;
}
Microsoft Visual C++ Runtime Library:
Expression: invalid comparator
New contributor
gbdj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.