Skip to content

Instantly share code, notes, and snippets.

@luoyetx
Last active December 25, 2015 22:39
Show Gist options
  • Select an option

  • Save luoyetx/7051898 to your computer and use it in GitHub Desktop.

Select an option

Save luoyetx/7051898 to your computer and use it in GitHub Desktop.
quick sort algorithm
void qsort(int *a, int l, int r)
{
int i, j, mid;
i = l; j = r;
mid = a[(i + j)/2];
do {
while (a[i] < mid) i++;
while (a[j] > mid) j--;
if (i <= j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
i++; j--;
}
}while (i<=j);
if (l < j) qsort(a, l, j);
if (i < r) qsort(a, i, r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment