Advertisement
balddenimhero

Ordered queue

Nov 13th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <queue>
  2. #include <iostream>
  3.  
  4. class IntOrder{
  5. public:
  6.     IntOrder(std::vector<int> o): o(o){}
  7.     bool operator() (int a, int b) const {return o[a%o.size()]<o[b%o.size()];}
  8. protected:
  9.     std::vector<int> o;
  10. };
  11.  
  12. class Foo{
  13. public:
  14.     Foo(IntOrder o, std::vector<int> ints):o(o),h(o){
  15.         for(auto i:ints)
  16.             h.push(i);
  17.     }
  18. protected:
  19.     IntOrder o;
  20.     std::priority_queue<int, std::vector<int>, IntOrder> h;
  21. };
  22.  
  23. int main() {
  24.     std::vector<int> ints = {0,1,2,3,4,5,6,7,8,9};
  25.  
  26.     auto o = IntOrder({0,2,4,6,8});
  27.     auto foo = new Foo(o, ints);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement