1: //make_heap2a.cpp
3: #include <iostream>
4: #include <vector>
5: #include <algorithm>
6: #include <functional>
7: using namespace std;
9: int main()
10: {
11: cout << "\nThis program illustrates the use of the STL make_heap() "
12: "algorithm (extended\nversion) to convert an arbitrary vector of "
13: "integers into a heap. In this case,\nthe built-in predicate "
14: "functor greater<int>() is used to order the values.";
15: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
17: int a[] = {25, 17, 36, 2, 3, 100, 1, 19, 7};
18: vector<int> v(a, a+9);
20: cout << "\nHere are the values in the vector:\n";
21: for (vector<int>::size_type i=0; i<v.size(); i++)
22: cout << v.at(i) << " ";
23: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
25: cout << "\nNow we make these values into a (minimum) heap.";
26: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
27: make_heap(v.begin(), v.end(), greater<int>());
29: cout << "\nHere are the revised contents of the vector:\n";
30: for (vector<int>::size_type i=0; i<v.size(); i++)
31: cout << v.at(i) << " ";
32: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
33: }