/* A simple sorting program. */ #include #include int doublearray_append(double **a,int *aspace,int *alen,double d) { if (*alen == *aspace) { int yspace = *aspace * 2 + 1; double *y = (double *) realloc(*a,yspace * sizeof(double)); if (!y) return 0; *a = y; *aspace = yspace; } (*a)[*alen] = d; ++*alen; return 1; } int main(void) { double *x = 0; int xspace = 0; int xlen = 0; double d; int i; int j; while (scanf("%lf",&d) == 1) if (!doublearray_append(&x,&xspace,&xlen,d)) { printf("out of memory\n"); exit(1); } while (xlen > 0) { j = 0; for (i = 1;i < xlen;++i) if (x[i] < x[j]) j = i; printf("%f\n",x[j]); x[j] = x[--xlen]; } return 0; }