std::is_heap( ) in C++ with Examples Last Updated : 21 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The std::is_heap() function in C++ Standard Template Library is used to check whether a given range of elements forms Max Heap or not. It returns True when given ranges of elements forms Max Heap, else it returns False. Header File: #include <algorithm> Syntax: is_heap(first, last) Parameter: It takes two parameters, iterators pointing towards the first and last element of the range. Return Value: The function returns the following value: True: If the elements in the range [first, last) forms a Max Heap. False: If the elements in the range [first, last) doesn't forms a Max Heap. Below is the program to illustrate std::is_heap(): Program 1: CPP // C++ program to illustrate // the std::is_heap() #include <algorithm> #include <iostream> #include <vector> using namespace std; // Driver Code int main() { // Given list of numbers vector<int> arr = { 3, 1, 5, 1, 9, 8 }; // Check if arr[] forms max-heap or not bool isHeap = is_heap(arr.begin(), arr.end()); if (isHeap) { cout << "Forms a Max Heap"; } else { cout << "Doesn't forms a Max Heap"; } } Output: Doesn't forms a Max Heap Program 2: CPP // C++ program to illustrate the std::is_heap() #include <algorithm> #include <iostream> #include <vector> using namespace std; // Driver Code int main() { // Given list of numbers vector<int> arr = { 3, 1, 5, 1, 9, 8 }; // Check if arr[] forms max-heap or not bool isHeap = is_heap(arr.begin(), arr.end()); // isHeap is false then make Max Heap // using in built function make_heap if (!isHeap) { make_heap(arr.begin(), arr.end()); } // Else already a heap else { cout << "Already Max Heap\n"; } // Print all the elements of arr // after make Max Heap for (auto& it : arr) { cout << it << ' '; } return 0; } Output: 9 3 8 1 1 5 Reference: http://www.cplusplus.com/reference/algorithm/is_heap/ Comment More infoAdvertise with us K kivi Follow Improve Article Tags : C++ CPP-Functions Practice Tags : CPP Similar Reads Heap in C++ STL The heap data structure can be implemented in a range using STL which provides faster max or min item retrieval, and faster insertion and deletion on sorted data and also works as a sub-routine for heapsort.STL Functions for Heap Operationsmake_heap(): Converts given range to a heap.push_heap(): Arr 6 min read make_heap() in C++ STL make_heap() is used to transform a sequence into a heap. A heap is a data structure which points to highest( or lowest) element and making its access in O(1) time. Order of all the other elements depends upon particular implementation, but remains consistent throughout. This function is defined in t 3 min read sort_heap function in C++ The sort_heap( ) is an STL algorithm which sorts a heap within the range specified by start and end. Sorts the elements in the heap range [start, end) into ascending order. The second form allows you to specify a comparison function that determines when one element is less than another. Defined in h 3 min read std::is_heap( ) in C++ with Examples The std::is_heap() function in C++ Standard Template Library is used to check whether a given range of elements forms Max Heap or not. It returns True when given ranges of elements forms Max Heap, else it returns False. Header File: #include <algorithm> Syntax: is_heap(first, last) Parameter: 2 min read Like