diff --git a/algorithm/is_heap.md b/algorithm/is_heap.md new file mode 100644 index 00000000..a07d0de6 --- /dev/null +++ b/algorithm/is_heap.md @@ -0,0 +1,31 @@ +# is_heap + +**Description :** The C++ function `std::is_heap` returns `true` if the elements in the range `[first, last)` form a _max heap_, such as is constructed by _make_heap_, and `false` otherwise. + +**Example :** + +```cpp +#include +#include +#include + +int main() +{ + std::vector v { 8, 6, 7, 5, 3, 0, 9 }; + + std::cout << "Intial value for v: "; + for (auto i : v) std::cout << i << ' '; + std::cout << '\n'; + + if (!std::is_heap(v.begin(), v.end())) { + std::cout << "Creating heap:\n"; + std::make_heap(v.begin(), v.end()); + } + + std::cout << "After call to make_heap, v: "; + for (auto i : v) std::cout << i << ' '; + std::cout << '\n'; +} +``` + +**[Run Code](https://rextester.com/CWLO88991)**