+ 1
Priority Queue With Pair | Facing Issue
Hi Please refer code below: I have priority queue of pair. pair is of score(integer) and id (integer). I need to sort data in pair as below: highest priority for higher score if score is same, highest priority is for lowest id It is not working for me even though I have overloaded < operator for pair. If I created struct for score and id , it is working as expected. What I am missing in pair implementation so that I get desired output? https://code.sololearn.com/ciRNL7QTd7vd/?ref=app
2 Answers
+ 2
just declare "operator<" inside the namespace "std":
namespace std {
bool operator<(const pair<int, int>& p1, const pair<int, int>& p2) {
if (p1.first != p2.first) // score
return p1.first < p2.first;
// return p1.second < p2.second;
return p1.second > p2.second;
}
} // namespace std
+ 2
Thanks MO ELomari