In: Computer Science
Building a Priority Queue in C++ using a min-heap.
Not using C++ Standard Template Library.
Trying to understand how this works. Thank you
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
#include <bits/stdc++.h>
using namespace std;
// Driver code
int main ()
{
// Creates a min heap
priority_queue <int, vector<int>, greater<int> > pq;
pq.push(5);
pq.push(1);
pq.push(10);
pq.push(30);
pq.push(20);
// One by one extract items from min heap
while (pq.empty() == false)
{
cout << pq.top() << " ";
pq.pop();
}
return 0;
}
Kindly revert for any queries
Thanks.