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

Commit

Permalink
Merge pull request #440 from UberschallSamsara/AddIsHeap
Browse files Browse the repository at this point in the history
Add is_heap.md for upstream repo issue #31
  • Loading branch information
Bhupesh-V authored Nov 12, 2019
2 parents cb80017 + e56786c commit 2d9e57b
Showing 1 changed file with 31 additions and 0 deletions.
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)**

0 comments on commit 2d9e57b

Please sign in to comment.