#include /* insertion sort, version one */ void sort(int *a, int size) { int i, insplace, j, t; for (i = 0; i < size; i++) { /* insert element a[i] in a[0 to i-1] */ /* * stash the element because we will overwrite it when we move * everything up */ t = a[i]; /* find place to insert */ for (insplace = 0; insplace < i && a[insplace] < t; insplace++) ; /* make room for the insertion (move everything up) */ for (j = i; j > insplace; j--) a[j] = a[j-1]; /* put it in that place we just moved everything up from */ a[insplace] = t; } } int main() { int i, a[10]; for (i = 0; i < 10; i++) scanf("%d", &a[i]); sort(a, 10); for (i = 0; i < 10; i++) printf("%d\n", a[i]); return 0; }