Skip to content

Instantly share code, notes, and snippets.

@afishr
Created September 17, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afishr/1b711f4ff66354ebb8fd401269c6611f to your computer and use it in GitHub Desktop.
Save afishr/1b711f4ff66354ebb8fd401269c6611f to your computer and use it in GitHub Desktop.
// 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