Skip to content

Commit

Permalink
Merge pull request #679 from Sagun-png/patch-5
Browse files Browse the repository at this point in the history
Priority Queue.cpp
  • Loading branch information
keshavsingh4522 authored Oct 2, 2021
2 parents cb51a84 + 4e0843d commit d7c1ec8
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 d7c1ec8

Please sign in to comment.