SkyHawk

Quick Sort

Jul 6th, 2011
537
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void quickSortR(int* a, int N) {
  2.     int i = 0, j = N-1;
  3.     int temp, p;
  4.     p = a[N>>1];
  5.     do{
  6.         while ( a[i] < p ) i++;
  7.         while ( a[j] > p ) j--;
  8.         if (i <= j)
  9.         {
  10.             temp = a[i]; a[i] = a[j]; a[j] = temp;
  11.             i++; j--;
  12.         }
  13.     }while(i<=j);
  14.     if ( j > 0 ) quickSortR(a, j+1);
  15.     if ( N-1 > i ) quickSortR(a+i, N-i);
  16. }
RAW Paste Data