SHARE
TWEET

Untitled

a guest Jan 24th, 2020 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdlib>
  2. #include <ctime>
  3. using namespace std;
  4. int partition(int a[113], int l, int r, int n)
  5. {
  6.     int ind=rand();
  7.     ind%=(n-1);
  8.     int v=a[ind];
  9.     int i=l;
  10.     int j=r;
  11.     while(i<=j)
  12.     {
  13.     while(a[i]<v)++i;
  14.     while(a[j]>v)--j;
  15.     if(i>=j)return j;
  16.     swap(a[i++], a[j--]);
  17.     }
  18.     return j;
  19. }
  20. void quicksort (int a[113], int l, int r, int n)
  21. {
  22.     if(l<r)
  23.     {
  24.         int q=partition(a, l, r, n);
  25.         quicksort(a, l, q, n);
  26.         quicksort(a, q+1, r, n);
  27.     }
  28. }
  29. int main()
  30. {
  31.     srand(time(NULL));
  32.     ios::sync_with_stdio(0);
  33.     ios_base::sync_with_stdio(0);
  34.     cin.tie(0);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top