Why is maxHeap initialisation syntax different from minHeap through priority_queue?

59 views Asked by At

I was trying to create a minHeap using the regular syntax but found out that

maxHeap is initialised as:

priority_queue<int> maxHeap;

whereas minHeap is initailised as:

priority_queue<int, vector<int>, greater<int>> minHeap;

Any idea to why is it so in C++? It could have been much easier to remember if minHeap and maxHeap were initialised using similar syntax.

1

There are 1 answers

0
Mooing Duck On BEST ANSWER

The priority_queue defaults to a max heap, so priority_queue<int> is shorthand for priority_queue<int, vector<int>, less<int>>, which does indeed match the min heap syntax