-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from Sagun-png/patch-5
Priority Queue.cpp
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |