// from Etter section 5.6 /*----------------------------------------------------------*/ /* This function sorts an array x with npts values into */ /* ascending order. */ void sort(int x[], int npts) { /* Declare variables. */ int k, j, m; int hold; /* Implement selection sort algorithm. */ for (k=0; k<=npts-2; k++) { /* Exchange minimum with next array value. */ m = k; for (j=k+1; j<=npts-1; j++) if (x[j] < x[m]) m = j; hold = x[m]; x[m] = x[k]; x[k] = hold; } /* Void return. */ return; } /*-------------------------------------------------------------*/