forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add is_heap.md for upstream repo issue Bhupesh-V#31
- Loading branch information
1 parent
df6e750
commit b626e6c
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)** |