Advertisement
Guest User

prosty_kopiec

a guest
Jun 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. vector<int> heap;
  9.  
  10. int commands;
  11.  
  12. string option;
  13. int number;
  14.  
  15. cin >> commands;
  16.  
  17. for (int i = 0; i < commands; i++) {
  18. cin >> option;
  19.  
  20. if (option == "push") {
  21. cin >> number;
  22. heap.push_back(number);
  23. push_heap(heap.begin(), heap.end());
  24. }
  25.  
  26. if (option == "pop") {
  27. if (!heap.empty()) {
  28. pop_heap(heap.begin(), heap.end());
  29. heap.pop_back();
  30. }
  31. }
  32.  
  33. if (option == "top") {
  34. if (!heap.empty()) {
  35. cout << heap.front() << endl;
  36. }
  37. }
  38. }
  39.  
  40. cout << "all done" << endl;
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement