function template
<algorithm>
std::is_heap default (1)template <class RandomAccessIterator> bool is_heap (RandomAccessIterator first, RandomAccessIterator last);custom (2)
template <class RandomAccessIterator, class Compare> bool is_heap (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
Test if range is heap
Returnstrue
if the range [first,last)
forms a heap, as if constructed with make_heap.
The elements are compared using operator<
for the first version, and comp for the second.
[first,last)
, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
bool
. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines.
true
if the range [first,last)
is a heap (as if constructed with make_heap), false
otherwise.
If the range [first,last)
contains less than two elements, the function always returns true
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// is_heap example
#include <iostream> // std::cout
#include <algorithm> // std::is_heap, std::make_heap, std::pop_heap
#include <vector> // std::vector
int main () {
std::vector<int> foo {9,5,2,6,4,1,3,8,7};
if (!std::is_heap(foo.begin(),foo.end()))
std::make_heap(foo.begin(),foo.end());
std::cout << "Popping out elements:";
while (!foo.empty()) {
std::pop_heap(foo.begin(),foo.end()); // moves largest element to back
std::cout << ' ' << foo.back(); // prints back
foo.pop_back(); // pops element out of container
}
std::cout << '\n';
return 0;
}
Popping out elements: 9 8 7 6 5 4 3 2 1
[first,last)
are accessed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4