Doubt in the comparator class?

Why does -
return A.age > B.age;
give the ages in ascending order, shouldn’t it be in descending order?

Hi, please note that by default priority_queue in C++ is max heap. So it returns the maximum according to the operator <.

For the case when we switch the operator, it returns the maximum according to the operator > which basically means the smallest element.

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.