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
Q1: I didn't look in the standard, but AFAIK, using vector
(or deque
btw), the complexity would be O(1)
for top()
, O(log n)
for push()
and pop()
. I once compared std::priority_queue
with my own heap with O(1)
push()
and top()
and O(log n)
pop()
and it certainly wasn't as slow as O(n)
.
Q2: set
is not usable as underlying container for priority_queue
(not a Sequence), but it would be possible to use set to implement a priority queue with O(log n)
push()
and pop()
. However, this wouldn't probably outperform the std::priority_queue
over std::vector
implementation.