In sorting, a comparator(a,b) returns bool value of whether a should appear b or not and we can define any comparison in it.
In priority queue, why isn’t it the same? For example. in greater, it is supposed to return bool value corresponding to whether (a>b?). Thus, if it is true (a is greater) and we follow the same definition of comparator return value that a should appear before b as comparator returns true, why does it not form a max heap but rather a min heap?
Comparator in sorting vs priority queue
Hey @roopali1710
Can you please send a code for the same. In my experience this should not happen. Might be some other reason. With the code we can better analyse the case.
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.