std::is_heap
cppreference.com
[] |
Google. . , . , . |
<metanoindex/>
<tbody> </tbody> template< class RandomIt > bool is_heap( RandomIt first, RandomIt last ); |
(1) | |
template< class RandomIt, class Compare > bool is_heap( RandomIt first, RandomIt last, Compare comp ); |
(2) | |
,
[first, last). is_heap operator< , comp.:
The first version of
is_heap uses operator< to compare elements, whereas the second uses the given comparison function comp.| first, last | ||
| comp | (.. , Compare), true, "", .:
| |
-RandomIt RandomAccessIterator.
| ||
'
[f,l), :*fstd::push_heap()std::pop_heap()
, .
#include <iostream>
#include <algorithm>
int main()
{
std::vector<int> v { 3, 1, 4, 1, 5, 9 };
std::cout << "initially, v: ";
for (auto i : v) std::cout << i << ' ';
std::cout << '\n';
if (!std::is_heap(v.begin(), v.end())) {
std::cout << "making heap...\n";
std::make_heap(v.begin(), v.end());
}
std::cout << "after make_heap, v: ";
for (auto i : v) std::cout << i << ' ';
std::cout << '\n';
}
:
initially, v: 3 1 4 1 5 9
making heap...
after make_heap, v: 9 5 4 1 1 3
.
(C++11) |
, ( ) |