1: //is_heap_until1a.cpp 3: #include <iostream> 4: #include <iomanip> 5: #include <vector> 6: #include <algorithm> 7: using namespace std; 9: int main() 10: { 11: cout << "\nThis program illustrates the use of the STL " 12: "is_heap_until() algorithm from\n<algorithm> to " 13: "find the first integer (if any) that destroys the " 14: "(default)\nmaximum heap order of a vector of integers."; 15: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 17: int a[] = {17, 12, 15, 9, 6, 14, 8, 3, 5}; 18: int b[] = {17, 12, 15, 9, 14, 6, 8, 3, 5}; 19: vector<int> va(a, a+9); 20: vector<int> vb(b, b+9); 21: cout << boolalpha; 22: auto firstNonHeapElementIter = is_heap_until(va.begin(), va.end()); 23: if (firstNonHeapElementIter == va.end()) 24: cout << "For 17, 12, 15, 9, 6, 14, 8, 3, 5, the sequence is " 25: "a maximum heap." << endl; 26: else 27: cout << "For 17, 12, 15, 9, 6, 14, 8, 3, 5, the maximum heap order " 28: "was destroyed\nat element " << *firstNonHeapElementIter << ".\n"; 30: firstNonHeapElementIter = is_heap_until(vb.begin(), vb.end()); 31: if (firstNonHeapElementIter == vb.end()) 32: cout << "For 17, 12, 15, 9, 14, 6, 8, 3, 5, the sequence is sorted " 33: "(in ascending order)." << endl; 34: else 35: cout << "For 17, 12, 15, 9, 14, 6, 8, 3, 5, the maximum heap order " 36: "was destroyed\nat element " << *firstNonHeapElementIter << ".\n"; 37: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 38: }