Advertisement
Guest User

Custom order of ints

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