Advertisement
apl-mhd

heap data structure priority queue

May 7th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <stack>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <climits>
  8. #include <utility>
  9.  
  10. #define MAX_SZ 100
  11.  
  12. using  namespace std;
  13.  
  14. struct  compare{
  15.  
  16.     bool operator()(const int& lhs, const int& rhs) const {
  17.  
  18.         return lhs >rhs;
  19.  
  20.     }
  21. };
  22.  
  23. struct  A{
  24.  
  25.     int a,b;
  26.  
  27.     bool operator()(const A& rhs)const {
  28.  
  29.         return b<rhs.b;
  30.     }
  31.  
  32. };
  33.  
  34.  
  35.  
  36.  
  37. int main() {
  38.  
  39.  
  40.  
  41.     priority_queue<int,vector<int>, compare > pq;
  42.  
  43.  
  44.     pq.push(10);
  45.     pq.push(9);
  46.     pq.push(8);
  47.  
  48.     while(!pq.empty()){
  49.  
  50.         cout<<pq.top()<<endl;
  51.         pq.pop();
  52.     }
  53.  
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement