Reputation: 588
Both are container adaptors and both are defined in the header <queue>
still they both have different interfaces to access the 'first' element. I can understand the lack of a back
due to the constraints of the data structure but naming front
differently confuses me.
Upvotes: 4
Views: 1833
Reputation: 264461
Yes that's the point.
These are two different adapters. They "adapt" an underlying container to have a specific interface. These two classes "define" the interface that can then used by algorithms.
Why that terminology?
front
and back
. front
but probably to differentiate it from queue they choose top
. It probably has something to do with the implementation (as it is almost definitely a heap underneath the covers which just has a top
).Upvotes: 2
Reputation: 119229
The priority_queue
container adaptor is a convenience wrapper for the standard library's heap algorithms, using a sequence container as a classic binary heap. The name top
likely reflects this association; we speak of the "top" of a heap, since we visualize it as a heap-ordered binary tree, with the element of greatest priority at the root (top).
Upvotes: 2