#include /* insertion sort, version two */ 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]; /* simultaneously move stuff up and find where to insert */ for (j = i; j > 0 && a[j-1] > t; j--) a[j] = a[j-1]; /* put it in that place we just left empty (so to speak) */ a[j] = 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; }