Does changing a priority queue element result in resorting the queue?

前端 未结 4 1682
抹茶落季
抹茶落季 2021-01-02 16:58

I have a priority_queue, and I want to modify some of it\'s contents (the priority value), will the queue be resorted then?

It depends if it resorts on push/pop (mor

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 17:30

    Okay, after searching a bit I found out how to "resort" queue, so after each priority value change you need to call:

    std::make_heap(const_cast(&queue.top()),
         const_cast(&queue.top()) + queue.size(),
         ComparerClass());
    

    And queue must be then

    std::priority_queue,ComparerClass> queue;
    

    Hope this helps.

提交回复
热议问题