template <class RandomIter> void sort_heap( RandomIter xFirst, RandomIter xLast );
#include <algorithm>
template <class RandomIter, class Pred> void sort_heap( RandomIter xFirst, RandomIter xLast, Pred xComp );
#include <iostream> #include <vector> #include <algorithm> int main() { using namespace std; // Create a vector with random entries vector<int> qV; for (int i = 0; i < 10; ++i) { qV.push_back(rand() % 20); } // Output the original randomized vector vector<int>::iterator qIter; cout << "Random Vector: "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter << " "; } cout << endl; // Sort the entries into heap order make_heap(qV.begin(), qV.end()); // Output the heap vector cout << "Heap Vector : "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter << " "; } cout << endl; // Sort the heap vector sort_heap(qV.begin(), qV.end()); // Output the sorted vector cout << "Sorted Vector: "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter << " "; } cout << endl; // Keep the window open cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.