Advertisement
hurmawe

8.1

May 19th, 2022
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. void Qsort(vector<int> &a, int first, int last)
  5. {
  6.     int l, r, vr, x;
  7.     if (first < last)
  8.     {
  9.         x = a[(last + first) / 2];
  10.         l = first; r = last;
  11.         while (l <= r)
  12.         {
  13.             while (a[l] < x)l++;
  14.             while (a[r] > x)r--;
  15.             if (l <= r)
  16.             {
  17.                 vr = a[l];
  18.                 a[l] = a[r];
  19.                 a[r] = vr;
  20.                 l++; r--;
  21.             }
  22.         }
  23.         Qsort(a, first, r);
  24.         Qsort(a, l, last);
  25.     }
  26. }
  27. int main()
  28. {
  29. vector<int> array = { 6, 9,66,785,632,569,56,654,2,0, 31,23,33};
  30. Qsort(array, 0, array.size() - 1);
  31. for(int i=0;i<array.size();i++)
  32. cout<<array[i]<< " ";
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement