How can I create Min stl priority_queue?

amitlicht picture amitlicht · Mar 13, 2010 · Viewed 128.1k times · Source

The default stl priority queue is a Max one (Top function returns the largest element).

Say, for simplicity, that it is a priority queue of int values.

Answer

James McNellis picture James McNellis · Mar 13, 2010

Use std::greater as the comparison function:

std::priority_queue<int, std::vector<int>, std::greater<int> > my_min_heap;