1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// is_heap example
#include // std::cout
#include // std::is_heap_until, std::sort, std::reverse
#include // std::vector
int main () {
std::vector<int> foo {2,6,9,3,8,4,5,1,7};
std::sort(foo.begin(),foo.end());
std::reverse(foo.begin(),foo.end());
auto last = std::is_heap_until (foo.begin(),foo.end());
std::cout << "The " << (last-foo.begin()) << " first elements are a valid heap:";
for (auto it=foo.begin(); it!=last; ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
|