I am writing a priority queue that has its own comparator function. Every where I see following implementation and not able to figure out what's the rationale behind defining comparator function in class or struct?
struct CompareHeight {
bool operator()(pair<int, int> const p1, pair<int, int> const p2)
{
if(p1.first == p2.first)
return p1.second > p2.second;
return p1.first < p2.first;
}
};
int main(){
priority_queue<pair<int, int >, vector<pair<int,int> >, CompareHeight> p;
}
Edit 1 - why use class or struct directly define a comparator function just like main function and used it?