descending priority queue in c++ code example
Example 1: min heap priority queue c++
#include<queue>
std::priority_queue <int, std::vector<int>, std::greater<int> > minHeap;
Example 2: priority queue descending order c++
The priority queue gquiz is : 30 20 10 5 1
gquiz.size() : 5
gquiz.top() : 30
gquiz.pop() : 20 10 5 1
Example 3: Priority Queue using Min Heap in c++
#include <bits/stdc++.h>
using namespace std;
int main ()
{
priority_queue <int> pq;
pq.push(5);
pq.push(1);
pq.push(10);
pq.push(30);
pq.push(20);
while (pq.empty() == false)
{
cout << pq.top() << " ";
pq.pop();
}
return 0;
}