Or login with:
#include <algorithm> template < class RandomAccessIterator > void pop_heap( RandomAccessIterator first, RandomAccessIterator last ); template < class RandomAccessIterator, class BinaryPredicate > void pop_heap( RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate comp );Parameters:
| Parameter | Description |
|---|---|
| first | A random-access iterator addressing the position of the first element in the heap |
| last | A random-access iterator addressing the position one past the final element in the heap |
| comp | User-defined predicate function object that defines sense in which one element is less than another. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
[first, last) by switching the value in the position first and the value in the position last-1 and makes the subrange [first, last-1) into a heap.
The first version compares objects using operator< and the second compares objects using a function object comp.#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a[] = {100, 19, 36, 17, 3, 25, 1, 2, 7}; vector<int> v(a, a+9); cout <<"\nHere are the values in the vector (the heap):\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nNow we delete (pop) a value from the heap."; pop_heap(v.begin(), v.end()); cout <<"\nHere are the revised contents of the vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nNote that the value deleted from the heap is still " "\nin the vector (at the end of the vector)."; cout <<"\nSo, we should reduce the size of the vector by 1, which " "we now do, and\nthen display the vector, which is once again a heap, one more time."; v.resize(v.size()-1); cout <<"\nHere are the final contents of the vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; return 0; }
You must login to leave a messge