I am really confused on how the comparators for pq work in cpp. so my understanding of arrays are if we have something like
bool compare(int a, int b)
{
return a < b;
}
this is saying that a < b so if this is true that means a will come before b so we are ordering in ascending order.
Now switching over priority queues, if lets say we want a min heap, i would think we would want the relation to be a < b, meaning a is going to come before b in the heap which makes sense to me logically but in actual reality the way to implement a min heap is:
bool minHeapCompare(int a, int b) {
return a > b;
}
i dont really understand this because this will return true if a > b so then a will be before b is this not a max heap??
If someone could clarify this and also explain how it works that would be great thanks.
I get this is the way it is, but I just dont really get why its like this.