PA2-zkouska/heap.cpp

27 lines
634 B
C++

#include <vector>
#include <algorithm>
#include <iostream>
int main() {
std::vector<int> v = {3, 5, 1, 2, 9, 0, 6, 15};
//* init
std::make_heap(v.begin(), v.end(), std::greater<int>());
//* pop
std::cout << "1: " << v.front() << '\n';
std::pop_heap(v.begin(), v.end(), std::greater<int>());
v.pop_back();
//* push
v.push_back(666);
std::push_heap(v.begin(), v.end(), std::greater<int>());
int i = 2;
while (v.size()) {
std::cout << i++ << ": " << v.front() << '\n';
std::pop_heap(v.begin(), v.end(), std::greater<int>());
v.pop_back();
}
return 0;
}