Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

pop_heap()

Module:  Standard C++ Library   Library:  Algorithms


Function

Local Index

No Entries

Summary

Algorithm that moves the largest element off the heap

Synopsis

#include <algorithm>

namespace std {
template <class RandomAccessIterator>
  void
  pop_heap(RandomAccessIterator start,
           RandomAccessIterator finish);

template <class RandomAccessIterator, class Compare>
  void
  pop_heap(RandomAccessIterator start,
           RandomAccessIterator finish, Compare comp);
}

Description

A heap is a particular organization of elements in a range between two random access iterators [a, b). Its two key properties are:

  1. *a is the largest element in the range.

  2. *a may be removed by the pop_heap() algorithm or a new element may be added by the pop_heap() algorithm, in O(log(N)) time.

These properties make heaps useful as priority queues.

The pop_heap() algorithm uses operator<() as the default comparison. An alternate comparison operator can be specified to the second overload of the function template.

The pop_heap() algorithm can be used as part of an operation to remove the largest element from a heap. It assumes that the range [start, finish) is a valid heap (in other words, that start is the largest element in the heap or the first element based on the alternate comparison operator). It then swaps the value in the location start with the value in the location finish - 1 and makes the range [start, finish - 1) back into a heap.

Complexity

pop_heap() performs at most 2 * log(finish - start) comparisons.

Example

See Also

make_heap(), push_heap(), sort_heap()

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.3.6.2



Previous fileTop of DocumentContentsIndex pageNext file

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.