1: //push_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 push_heap() " 12: "algorithm (extended\nversion) to add a value to a (minimum) " 13: "heap of integers."; 14: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 16: int a[] = {2, 3, 25, 7, 17, 100, 36, 19}; 17: vector<int> v(a, a+8); 19: cout << "\nHere are the values in the vector (the heap):\n"; 20: for (vector<int>::size_type i=0; i<v.size(); i++) 21: cout << v.at(i) << " "; 22: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 24: cout << "\nNow we add the value 1 to the heap."; 25: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 26: v.push_back(1); 27: push_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: }