## pop_heap
## Prototype
template <class RandomAccessIterator> void pop_heap(RandomAccessIterator first, RandomAccessIterator last); template <class RandomAccessIterator, class StrictWeakOrdering> inline void pop_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp); ## Description
The postcondition for the first version of ## DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h. ## Requirements on typesFor the first version: -
`RandomAccessIterator` is a model of RandomAccessIterator. -
`RandomAccessIterator` is mutable. -
`RandomAccessIterator` 's value type is a model of LessThanComparable. -
The ordering on objects of
`RandomAccessIterator` 's value type is a*strict weak ordering*, as defined in the LessThanComparable requirements.
For the second version: -
`RandomAccessIterator` is a model of RandomAccessIterator. -
`RandomAccessIterator` is mutable. -
`StrictWeakOrdering` is a model of StrictWeakOrdering. -
`RandomAccessIterator` 's value type is convertible to`StrictWeakOrdering` 's argument type.
## PreconditionsFor the first version: -
`[first, last)` is a valid range. -
`[first, last - 1)` is a valid range. That is,`[first, last)` is nonempty. -
`[first, last)` is a heap. That is,`is_heap(first, last)` is`true` .
For the second version: -
`[first, last)` is a valid range. -
`[first, last - 1)` is a valid range. That is,`[first, last)` is nonempty. -
`[first, last)` is a heap. That is,`is_heap(first, last, comp)` is`true` .
## ComplexityLogarithmic. At most ## Exampleint main() { int A[] = {1, 2, 3, 4, 5, 6}; const int N = sizeof(A) / sizeof(int); make_heap(A, A+N); cout << "Before pop: "; copy(A, A+N, ostream_iterator<int>(cout, " ")); pop_heap(A, A+N); cout << endl << "After pop: "; copy(A, A+N-1, ostream_iterator<int>(cout, " ")); cout << endl << "A[N-1] = " << A[N-1] << endl; } The output is Before pop: 6 5 3 4 2 1 After pop: 5 4 3 1 2 A[N-1] = 6 ## Notes[1] A heap is a particular way of ordering the elements in a range of RandomAccessIterator [2] ## See also |