fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. priority_queue<int> pq;
  7. pq.push(1);
  8. pq.push(5);
  9. pq.push(2);
  10. pq.push(6);
  11.  
  12. cout << pq.top(); // print 6
  13. cout << endl;
  14. pq.pop();
  15. cout << pq.top(); // print 5
  16. cout << endl;
  17.  
  18. priority_queue<pair<int,int>> pq2;
  19. pq2.push({1, 5});
  20. pq2.push({1, 6});
  21. pq2.push({1, 7});
  22. cout << pq2.top().first << " " << pq2.top().second << endl;
  23.  
  24. priority_queue<int, vector<int>, greater<int>> pq3; // min pq
  25. pq3.push(1);
  26. pq3.push(5);
  27. pq3.push(2);
  28. pq3.push(6);
  29.  
  30. cout << pq3.top() << endl; // prints 1
  31.  
  32. priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq4;
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
6
5
1 7
1