Skip to content

Instantly share code, notes, and snippets.

@Rexagon
Created December 8, 2016 07:38
Show Gist options
  • Save Rexagon/b04bc322358f1bc425b63dc45ca4ab03 to your computer and use it in GitHub Desktop.
Save Rexagon/b04bc322358f1bc425b63dc45ca4ab03 to your computer and use it in GitHub Desktop.
Just simple quicksort with right element as pivot
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