Skip to content

Commit

Permalink
Create Priority Queue.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagun-png authored Oct 2, 2021
1 parent 895538c commit 4e0843d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions CPP/Priority Queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int main()
{
{
priority_queue<int> q;
for(int elm: {1,8,5,6,3,4})
q.push(elm);
while(!q.empty()){
cout<<q.top()<<" ";
q.pop();
}
cout<<endl;
}
{
priority_queue<int, vector<int>, greater<int>> q2;
for(int elm: {1,8,5,6,3,4})
q2.push(elm);
while(!q2.empty()){
cout<<q2.top()<<" ";
q2.pop();
}
cout<<endl;
}
{
auto cmp=[] (int left, int right) { return(left) < (right);};
priority_queue<int, vector<int>, decltype(cmp)> q3(cmp);
for(int elm: {1,8,5,6,3,4})
q3.push(elm);
while(!q3.empty()){
cout<<q3.top()<<" ";
q3.pop();
}
cout<<endl;
}
}

0 comments on commit 4e0843d

Please sign in to comment.