Skip to content

Commit

Permalink
Add is_heap.md for upstream repo issue Bhupesh-V#31
Browse files Browse the repository at this point in the history
  • Loading branch information
UberschallSamsara committed Nov 1, 2019
1 parent df6e750 commit b626e6c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions algorithm/is_heap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.
```cpp
template <class RandomAccessIterator>
bool is_heap (RandomAccessIterator first, RandomAccessIterator last);
```
**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 b626e6c

Please sign in to comment.