SHARE
TWEET

QUICKSORT

sonprao Sep 16th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void sort(int *a,int l, int r)
  2. {
  3.     int i,j,x,y;
  4.     i=l;
  5.     j=r;
  6.     x=a[(l+r)/2];
  7.     while (i<=j)
  8.     {
  9.         while (a[i]<x) i++;
  10.         while (x<a[i]) j--;
  11.         if (i<=j)
  12.         {
  13.             y=a[i];
  14.             a[i]=a[j];
  15.             a[j]=y;
  16.             i++;
  17.             j--;
  18.         }
  19.     }
  20.     if (l<j) sort(l,j);
  21.     if (i<r) sort(i,r);
  22. }
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