Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void my_sort(auto &a, auto cmp, auto my_swap)
  7. {
  8.     for (int i = 0; i < a.size(); ++i)
  9.     {
  10.         auto prev = begin(a);
  11.         for (auto j = begin(a); j != end(a); ++j)
  12.         {
  13.             if (cmp(*j, *prev))
  14.                 my_swap(*j, *prev);
  15.             prev = j;
  16.         }
  17.     }
  18. }
  19.  
  20. int main()
  21. {
  22.     vector<int> a;
  23.     int n = 10;
  24.     for (int i = 0; i < n; ++i)
  25.         a.push_back(i);
  26.     my_sort(a,
  27.     [](auto a, auto b)
  28.     {
  29.         return a > b;
  30.     },
  31.     [](auto &a, auto &b)
  32.     {
  33.         a ^= b ^= a ^= b;
  34.     }
  35.     );
  36.  
  37.     for (int i = 0; i < n; ++i)
  38.         cout << a[i] << ' ';
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement