Efficiency of the STL priority_queue

前端 未结 6 1196
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 06:11

I have an application (C++) that I think would be well served by an STL priority_queue. The documentation says:

Priority_queue is a cont

6条回答
  •  暖寄归人
    2020-11-30 07:15

    No. This is not correct. top() is O(1) and push() is O(log n). Read note 2 in the documentation to see that this adapter does not allow iterating through the vector. Neil is correct about pop(), but still this allows working with the heap doing insertions and removals in O(log n) time.

提交回复
热议问题