How priority queue arrange of data which are in pair?

in the question (given below) how priority queue is going to arrange data which are in pairs?

What will be the output of following C++ code?

#include <bits/stdc++.h>

using namespace std;
int main()
{
priority_queue<pair<int, int> >q;
q.push( {1, 5} );
q.push( {4, 2} );
q.push( {5, 3} );
q.push({2, 4});
q.push({3, 1});
q.push({5, 2});
cout<<q.top().first<<" "<<q.top().second<<endl;
return 0;
}

It will make a priority queue based on the first element of the pair by default. So it it is a maxheap, it will form a maxheap depending on the first element of the pair.

@prakrat hey,isme pair ke first element ke basis pr kam hota hai ,in the codeg given by you ,max heap is taken so 5 maximum hai to first element jo panch hai woh do pair hai to ab in dono ke 2nd element ko compare krenge jo bda hai woh ans hoga that is 5,3.

1 Like

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.