/* selection sort function for type double array -- see p. 397 */ void select_sort(double list[], /* input/output - array being sorted */ int n) /* input - number of elements to sort */ { int fill; /* first element of unsorted array */ double temp; /* temporary storage */ int index_of_min; /* subscript of next smallest element */ for (fill = 0; fill < n - 1; fill++) { /* Find position of smallest element in unsorted array */ index_of_min = get_min_range(list, fill, n-1); /* Exchange elements at fill and index_of_min */ temp = list[index_of_min]; list[index_of_min] = list[fill]; list[fill] = temp; } } /* end select_sort */ /* function get_min_range - called by select_sort * Finds the index of the smallest value of the elements * in array list with subscripts first through last. * Based on function get_max, p. 374 */ int get_min_range(double list[], int first, int last) { int sub; /* subscript which goes from first through last */ int index_min_so_far; /* subscript of smallest so far */ index_min_so_far = first; /* assume first element is smallest */ for (sub = first+1; sub <= last; sub++) if (list[sub] < list[index_min_so_far]) index_min_so_far = sub; /* new smallest element */ return index_min_so_far; } /* end get_min_range */