Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Add is_heap.md for upstream repo issue #31 #440

Merged
merged 2 commits into from
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions algorithm/is_heap.md
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
#include <iostream>
#include <vector>

int main()
{
std::vector<int> 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)**