-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpriority_queue.cpp
More file actions
41 lines (32 loc) · 1.02 KB
/
priority_queue.cpp
File metadata and controls
41 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//priority queue operations
//priority queue max heap and min heap
#include<bits/stdc++.h>
using namespace std;
void printPQ(priority_queue<int> temp) //print max heap
{
while(!temp.empty())
{
cout<<temp.top()<<" "; //printing the topmost element of priority queue
temp.pop(); //delete the topmost element
}
}
void printPQ(priority_queue<int,vector<int>,greater<int> > temp) //print min heap
{
while(!temp.empty())
{
cout<<temp.top()<<" "; //printing the topmost element of priority queue
temp.pop(); //delete the topmost element
}
}
int main()
{
priority_queue<int> pq; //max heap - elements in descending order
for(int i=10;i>=0;i--)pq.push(i*10); //insertion to max heap
cout<<"Max heap priority queue : \n";
printPQ(pq);
priority_queue<int,vector<int>,greater<int> > pq1; // min heap-elements in descending order
for(int i=10;i>=0;i--)pq1.push(i*10); //insertion to min heap
cout<<"\nMin heap priority queue : \n";
printPQ(pq1);
return 0;
}