Skip to content

Instantly share code, notes, and snippets.

@ta1hia
Created November 5, 2015 12:18
Show Gist options
  • Save ta1hia/905de504d5808176a9f2 to your computer and use it in GitHub Desktop.
Save ta1hia/905de504d5808176a9f2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void qsort(int *X, int L, int U) {
int T, M, i, tmp;
if (L < U) {
T = X[L];
M = L;
for (i = L+1; i < U; i++) {
if (X[i] < T) {
M += 1;
tmp = X[M];
X[M] = X[i];
X[i] = tmp;
}
}
X[L] = X[M];
X[M] = T;
qsort(X, L, M);
qsort(X, M+1, U);
}
}
int main(int argc, char *argv[]) {
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
int n = sizeof a / sizeof a[0];
int i;
for (i = 0; i < n; i++)
printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
qsort(a,0, n);
for (i = 0; i < n; i++)
printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment