Example 1 — A valid max-heap
Check a vector that follows the heap rule.
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {9, 5, 4, 1, 3};
bool ok = std::is_heap(v.begin(), v.end());
std::cout << std::boolalpha << "Heap: " << ok << '\n';
return 0;
} How It Works
- In a max-heap every value is at least as big as its children.
- 9 is above 5 and 4, and 5 is above 1 and 3.
- All checks pass, so the answer is
true.

