Advertisement
avisrivastava254084

Untitled

Oct 31st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. // C++ program to use priority_queue to implement min heap
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. // Driver code
  6. int main ()
  7. {
  8.     // Creates a min heap
  9.     priority_queue <int, vector<int>, greater<int> > pq;
  10.     pq.push(5);
  11.     pq.push(1);
  12.     pq.push(10);
  13.     pq.push(30);
  14.     pq.push(20);
  15.  
  16.     // One by one extract items from min heap
  17.     while (pq.empty() == false)
  18.     {
  19.         cout << pq.top() << " ";
  20.         pq.pop();
  21.     }
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement