This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from UberschallSamsara/AddIsHeap
Add is_heap.md for upstream repo issue #31
- Loading branch information
Showing
1 changed file
with
31 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,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)** |