1: //make_heap1a.cpp
3: #include <iostream>
4: #include <vector>
5: #include <algorithm>
6: using namespace std;
8: int main()
9: {
10: cout << "\nThis program illustrates the use of the STL make_heap() "
11: "algorithm (default\nversion) to convert an arbitrary vector of "
12: "integers into a heap.";
13: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
15: int a[] = {25, 17, 36, 2, 3, 100, 1, 19, 7};
16: vector<int> v(a, a+9);
18: cout << "\nHere are the values in the vector:\n";
19: for (vector<int>::size_type i=0; i<v.size(); i++)
20: cout << v.at(i) << " ";
21: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
23: cout << "\nNow we make these values into a (maximum) heap.";
24: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
25: make_heap(v.begin(), v.end());
27: cout << "\nHere are the revised contents of the vector:\n";
28: for (vector<int>::size_type i=0; i<v.size(); i++)
29: cout << v.at(i) << " ";
30: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
31: }