stl priority queue based on lower value first

前端 未结 6 1860
故里飘歌
故里飘歌 2020-12-18 15:35

I have a problem with stl priority queue.I want to have the priority queue in the increasing order,which is decreasing by default.Is there any way to do this in priority qu

6条回答
  •  轮回少年
    2020-12-18 16:30

    Use a different comparator as the 3rd template argument of std::priority_queue.

    priority_queue is a container adaptor that works on any sequence you define. The performance of insertion is equal to the std::push_heap operation and takes logarithmic time. So the complexity to sorting after all insertions are done isn't equal. If you insert a fixed amount and work the queue afterwards a vector and a single sort could be more efficient.

提交回复
热议问题