Last active
August 3, 2017 08:36
-
-
Save vigack/e5c213ab0ba494bd134d7b410ba98ae0 to your computer and use it in GitHub Desktop.
QuickSort-Lomuto's Version
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
void swap(int *a, int *b){ | |
int tmp; | |
tmp = *a; | |
*a = *b; | |
*b = tmp; | |
} | |
void quickSort(int left, int right, int *arr){ | |
// base | |
if(left>=right) | |
return; | |
int i, j; | |
int pivot, tmp; | |
pivot = arr[right]; | |
i = left; | |
while(i<right&&arr[i]<pivot) | |
i++; | |
j = i+1; | |
while(j<right){ | |
if(arr[j]<pivot){ | |
swap(arr+j, arr+i); | |
i++; | |
} | |
j++; | |
} | |
swap(arr+i, arr+right); | |
// sort left and right part | |
quickSort(left, i-1, arr); | |
quickSort(i+1, right, arr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment