diff --git a/heap.cpp b/heap.cpp new file mode 100644 index 0000000..d63e3dc --- /dev/null +++ b/heap.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +int main() { + std::vector v = {3, 5, 1, 2, 9, 0, 6, 15}; + + //* init + std::make_heap(v.begin(), v.end(), std::greater()); + + //* pop + std::cout << "1: " << v.front() << '\n'; + std::pop_heap(v.begin(), v.end(), std::greater()); + v.pop_back(); + + //* push + v.push_back(666); + std::push_heap(v.begin(), v.end(), std::greater()); + + int i = 2; + while (v.size()) { + std::cout << i++ << ": " << v.front() << '\n'; + std::pop_heap(v.begin(), v.end(), std::greater()); + v.pop_back(); + } + return 0; +} \ No newline at end of file