+ 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

24th Dec 2022, 4:07 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Antworten
+ 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
25th Dec 2022, 1:41 PM
MO ELomari
MO ELomari - avatar
+ 2
Thanks MO ELomari
25th Dec 2022, 2:26 PM
Ketan Lalcheta
Ketan Lalcheta - avatar