fork download
  1. //
  2. // main.cpp
  3. // Priority Queue
  4. //
  5. // Created by Himanshu on 19/09/21.
  6. //
  7.  
  8. #include <iostream>
  9. #include <queue>
  10. using namespace std;
  11.  
  12. int main () {
  13.  
  14. priority_queue<int> pq;
  15.  
  16. cout<<"Insert Q(x) {30, 100, 25, 40}"<<endl;
  17. pq.push(30);
  18. pq.push(100);
  19. pq.push(25);
  20. pq.push(40);
  21.  
  22. cout<<"Maximum Element (Q)"<<endl;
  23. cout<<pq.top()<<endl;
  24.  
  25. cout<<"Maximum Element (Q) after Extract-Max (Q)"<<endl;
  26. pq.pop();
  27. cout<<pq.top()<<endl;
  28.  
  29. cout <<"Extracting out elements..."<<endl;
  30. while (!pq.empty()) {
  31. cout<< pq.top()<<" ";
  32. pq.pop();
  33. }
  34. cout<<endl;
  35.  
  36. if (pq.empty()) {
  37. cout<<"Priority queue is empty"<<endl;
  38. } else {
  39. cout<<"Priority queue is not empty"<<endl;
  40. }
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5512KB
stdin
Standard input is empty
stdout
Insert Q(x) {30, 100, 25, 40}
Maximum Element (Q)
100
Maximum Element (Q) after Extract-Max (Q)
40
Extracting out elements...
40 30 25 
Priority queue is empty