Created
December 8, 2016 07:38
-
-
Save Rexagon/b04bc322358f1bc425b63dc45ca4ab03 to your computer and use it in GitHub Desktop.
Just simple quicksort with right element as pivot
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 quicksort(int arr[], int left, int right) | |
{ | |
if (left < right) { | |
int pivot = arr[right]; | |
int i = left - 1; | |
for (int j = left; j <= right-1; j++) | |
{ | |
if (arr[j] <= pivot) | |
{ | |
i++; | |
int temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
} | |
} | |
int temp = arr[i + 1]; | |
arr[i + 1] = arr[right]; | |
arr[right] = temp; | |
quicksort(arr, left, i); | |
quicksort(arr, i+1, right); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment