
正文
c++ 判断给定区间是否是一个heap. O(N) (is_heap)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
#include <iostream> // cout
#include <algorithm> // is_heap, make_heap, pop_heap
#include <vector> // vector
using namespace std;
int main () {
vector<int> foo {,,,,,,,,}; if (!is_heap(foo.begin(),foo.end()))
make_heap(foo.begin(),foo.end()); cout << "Popping out elements:";
while (!foo.empty()) {
pop_heap(foo.begin(),foo.end()); // moves largest element to back
cout << ' ' << foo.back(); // prints back
foo.pop_back(); // pops element out of container
}
cout << '\n'; return ;
}






