Doubt in Passing Compare Function

I was doing a problem on Codechef MINOPS MINOPS Problem - CodeChef .
I had my compare function for sorting vector of pairs as :

bool f(pair<int,int>&a,pair<int,int>&b){
if(a.second-a.first-1<=b.second-b.first-1){
return true;
}
return false;
}
The code showed run-time error SIGABRT.
Then I removed = from the compare function and made it as:
bool f(pair<int,int>&a,pair<int,int>&b){
if(a.second-a.first-1<b.second-b.first-1){
return true;
}
return false;
}
Then the code passed .
Link for My SIGABRT Submission : CodeChef: Practical coding for everyone
Link for My Passed Solution : CodeChef: Practical coding for everyone
The difference between both codes is just of = in compare function .
I want to know why this happened.Can anyone explain this ?

See this, and its comments

1 Like

The compare function you pass should be < operator. What happens with the = is that a<b and b>a if a==b. So the sort function crashes.

1 Like