template <class RandomAccessIterator> void pop_heap( RandomAccessIterator xFirst, RandomAccessIterator xLast );
#include <algorithm>
template <class RandomAccessIterator, class BinaryPred> void pop_heap( RandomAccessIterator xFirst, RandomAccessIterator xLast, BinaryPred xComp );
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
using namespace std;
// Create a vector instance
vector<int> qV;
qV.push_back(45);
qV.push_back(83);
qV.push_back(3);
qV.push_back(49);
qV.push_back(97);
qV.push_back(16);
qV.push_back(34);
qV.push_back(51);
vector<int>::iterator qIter;
// Make the vector a heap
make_heap(qV.begin(), qV.end());
// Output the heap
cout << "Output the Heap : ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Pop the largest int (97) and put it last
pop_heap(qV.begin(), qV.end());
// Output the new vector
cout << "Output after Pop: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.