Tarango

struct type priority queue

Aug 10th, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define inf 99999999
  4.  
  5. struct lazy {
  6.     long long value;
  7.     int time;
  8.     lazy(long long val, int tm) {
  9.         value = val;
  10.         time = tm;
  11.     }
  12.     bool operator<(const lazy& rhs) const{
  13.         if(time>rhs.time) return true;
  14.         return false;
  15.     }
  16. };
  17.  
  18. int main(){
  19.     //For struct type priority queue:
  20.     priority_queue<lazy> pq;
  21.     pq.push(lazy(3,76));
  22.     pq.push(lazy(9,9));
  23.     pq.push(lazy(3,7));
  24.     pq.push(lazy(2,1));
  25.     pq.push(lazy(3,65));
  26.     pq.push(lazy(5,71));
  27.  
  28.     while(pq.empty() == false){
  29.         lazy cur = pq.top();
  30.         pq.pop();
  31.         printf("Time: %d\n",cur.time);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment