/* selection.c -- Read an integer array, print it, then sort it and * print it. Use the selection sort method. */ #include #define NMAX 10 int getIntArray(int a[], int nmax, int sentinel); void printIntArray(int a[], int n); void selectionSort(int a[], int n); int main(void) { int x[NMAX]; int hmny; int who; int where; hmny = getIntArray(x, NMAX, 0); if (hmny==0) printf("This is the empty array!\n"); else{ printf("The array was: \n"); printIntArray(x,hmny); selectionSort(x,hmny); printf("The sorted array is: \n"); printIntArray(x,hmny); } } void printIntArray(int a[], int n) /* n is the number of elements in the array a. * These values are printed out, five per line. */ { int i; for (i=0; i0;rh--){ /*Find position of largest element in range 0..rh*/ where = 0; for (lcv=1;lcv<=rh;lcv++) if (a[lcv]>a[where]) where = lcv; temp = a[where]; a[where] = a[rh]; a[rh] = temp; } }