Skip to content

Instantly share code, notes, and snippets.

@luoyetx
Created March 15, 2015 01:58
Show Gist options
  • Save luoyetx/de78b6cc68c1e1d87a01 to your computer and use it in GitHub Desktop.
Save luoyetx/de78b6cc68c1e1d87a01 to your computer and use it in GitHub Desktop.
void qsort(int a[], int l, int r) {
int first, last, key;
first = l; last = r;
key = a[last];
while (first < last) {
while (first<last && a[first]<=key) first++;
a[last] = a[first];
while (first<last && a[last]>=key) last--;
a[first] = a[last];
}
a[first] = key;
if (l < first-1) qsort(a, l, first-1);
if (r > first+1) qsort(a, first+1, r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment