Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does queue have front but priority queue has top in stl?

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.

like image 489
Ankur S Avatar asked Oct 19 '25 07:10

Ankur S


1 Answers

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).

like image 102
Brian Bi Avatar answered Oct 20 '25 20:10

Brian Bi