Created
January 3, 2017 19:34
-
-
Save brun0xff/c3ba0acf96b7f5c3d5bea6bd3200938b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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