If we have a pair of <int, int>
in the priority queue, will it sort by first element or the second element in increasing order in the priority queue?
What does the greater<int> sort by default if we have a pair in our priority queue?
Whenever there is a pair of two integers and you try to sort an array of such pairs , the sorting is done by the comparison of first element by default.
You can use a comparator in case of sort() or functor in case of Priority Queue or other STL classes if you want the sorting to be done based on the second element or in any other fashion.
1 Like