Comparator Class

Hi ,

when in the Person Compare comparator class the instructor does

return A.age() <B.age()

then , it should mean that if A 's age is less than B’s age then return true that means A should be placed before B in the priority queue which implies that the priority queue should be a min priority queue(i.e. elements should come in ascending order) .However , the answer is coming in the descending order . Kindly explain this to me .I’m unable to understand this

this logic is valid for sorting

in heaps we do just opposite of sorting
in heaps we swap element to its parent when parent>child (in min heap) during heapify

so if you write
return A.age() <B.age()

it means you are making max priority queue when A’s age is smaller then you swap it will child during heapify

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved :grinning:

So this means that we are cosidering the model of a max heap internally and are accordingly writng the commands?

yes
priority queue internally works same as heap