Advertisement
Guest User

Untitled

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 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. string option;
  12. int number;
  13.  
  14. cin >> commands;
  15.  
  16. for (int i = 0; i < commands; i++) {
  17. cin >> option;
  18.  
  19. if (option == "push") {
  20. cin >> number;
  21. heap.push_back(number);
  22. push_heap(heap.begin(), heap.end());
  23. }
  24.  
  25. if (option == "pop") {
  26. if (!heap.empty()) {
  27. pop_heap(heap.begin(), heap.end());
  28. heap.pop_back();
  29. }
  30. }
  31.  
  32. if (option == "top") {
  33. if (!heap.empty()) {
  34. cout << heap.front() << endl;
  35. }
  36. }
  37. }
  38. cout << "all done" << endl;
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement