How does comparator function work with priority queue of pairs

I am having trouble with this problem.
How is the comparison happening in each call?
can you please explain it step by step?

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
struct Compare
{
bool operator()(pi const & a, pi const & b)
{
if(a.second < b.second)
{
return true;
}
else if(a.second > b.second)
{
return false;
}
else
{
if(a.first > b.first)
{
return true;
}
return false;
}
}
};
int main()
{
priority_queue<pi , vector, Compare>q;
q.push({1, 5});
q.push({5, 15});
q.push({7, 15});
q.push({10, 2});
q.push({1, 10});
cout<<q.top().first<<" "<<q.top().second<<endl;

return 0;

}

Hi, @alok_baluni
please look at the code https://ide.codingblocks.com/s/655425
I’ve added detailed comments and also changed inserted value ( in main ) so that you can understand it better.
Also look at the output by running the code you’ll be able to see how pairwise comparison is being done.

@alok_baluni is it clear now?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.