#include #include #include #include #include using namespace std; int gen_rnd(int min, int max) { return rand() % (max - min + 1) + min; } vector prepare(int length, int min, int max) { vector v; for (size_t i = 0; i < length; i++) { v.push_back(gen_rnd(min, max)); } return v; } void print(vector& v) { for (auto& n : v) { cout << n << " "; } cout << endl; } void insert(vector& v) { int n; cout << "n: "; cin >> n; v.push_back(n); push_heap(v.begin(), v.end()); } int main() { srand(time(nullptr)); vector v = prepare(10, 1, 100); print(v); make_heap(v.begin(), v.end()); print(v); insert(v); print(v); while (!v.empty()) { cout << v.front() << " "; pop_heap(v.begin(), v.end()); v.pop_back(); } return 0; }