Skip to content

Instantly share code, notes, and snippets.

@afishr afishr/quicksort.c
Created Sep 17, 2018

Embed
What would you like to do?
// Quicksort
template <typename T>
void quicksort(T arr, int l, int r)
{
int i, j;
i = l;
j = r;
int middle = arr[(i + j) / 2];
do
{
while (middle > arr[i])
i++;
while (middle < arr[j])
j--;
if ( i <= j)
{
swap(arr[i], arr[j]);
i++;
j--;
}
}
while (i < j);
if (i < r)
quicksort(arr, i, r);
if (j > l)
quicksort(arr, l, j);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.