Name
pop_heap function template — Removes largest element from a heap
Synopsis
template<typename RandIter> void pop_heap(RandIter first, RandIter last); template<typename RandIter, typename Compare> void pop_heap(RandIter first, RandIter last, Compare comp);
The pop_heap
function
template copies the first (largest) element from the heap in
[first
, last
) to the end of the range, that is,
*
(last
- 1). It then ensures that the
elements remaining in [first
,
last
- 1) form a heap.
The first form compares values using the <
operator. The second form calls
comp(*iter1
, *iter2)
.
Technical Notes
Precondition: [first,
last) is a heap (see make_heap
for the definition of a
heap).
Postcondition: [first, last - 1) is a heap, and !(*(last - 1) < *i) for all i in [first, last - 1).
Complexity is logarithmic: at most 2 × log(last - first) comparisons are performed.
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.