Skip to content

Instantly share code, notes, and snippets.

@brun0xff
Created January 3, 2017 19:34
Show Gist options
  • Save brun0xff/c3ba0acf96b7f5c3d5bea6bd3200938b to your computer and use it in GitHub Desktop.
Save brun0xff/c3ba0acf96b7f5c3d5bea6bd3200938b to your computer and use it in GitHub Desktop.
int partition( int a[], int l, int r) {
int pivot, i, j, t;
pivot = a[l];
i = l; j = r+1;
while(1){
do ++i; while( a[i] <= pivot && i <= r );
do --j; while( a[j] > pivot );
if( i >= j ) break;
t = a[i]; a[i] = a[j]; a[j] = t;
}
t = a[l]; a[l] = a[j]; a[j] = t;
return j;
}
void quickSort(int a[], int l, int r) {
int j;
if( l < r ){
j = partition( a, l, r);
quickSort( a, l, j-1);
quickSort( a, j+1, r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment