From C++ Primer and also https://en.cppreference.com/w/cpp/container/priority_queue, I know:
A priority_queue requires random access in addition to the front, push_back, and pop_back operations;
I also read this blog post from Google and know:
- push: add a new element to the queue,
- pop: remove the largest element of the queue,
- top: access the largest element of the queue.
push
should be implemented by push_back
, no problem.
And pop
and top
seem to operate on the same element. One is to access it, the other removes it. So I think these two operations should be implemented by pop_front()
and front()
or pop_back()
and back()
.
So I am confused, why are the requirements front()
and pop_back()
?
Let's for example assume the underlying container is a vector
and with some int elements let's say 1,2,3,4,5,6
. How does the adaptor interface "pop()
, top()
" work with the underlying "front()
, pop_back()
"?
push_back
,pop_back
andfront
. (push_back
is easy to understand of course)pop
is used to remove thetop
element. So I think the underlying operation should also target the same element, right? let's say avector
,pop_back()
andfront()
, does not target the same element.