How can I create Min stl priority_queue?

前端 未结 9 860
误落风尘
误落风尘 2020-12-04 04:49

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.

9条回答
  •  孤城傲影
    2020-12-04 05:51

    In C++11 you could also create an alias for convenience:

    template using min_heap = priority_queue, std::greater>;
    

    And use it like this:

    min_heap my_heap;
    

提交回复
热议问题