//DISPLAY 17.2 A Generic Sorting Function // This is file sortfunc.cpp template void swap_values(T& variable1, T& variable2) { T temp; temp = variable1; variable1 = variable2; variable2 = temp; } template int index_of_smallest(const BaseType a[], int start_index, int number_used) { BaseType min = a[start_index]; int index_of_min = start_index; for (int index = start_index + 1; index < number_used; index++) if (a[index] < min) { min = a[index]; index_of_min = index; //min is the smallest of a[start_index] through a[index] } return index_of_min; } template void sort(BaseType a[], int number_used) { int index_of_next_smallest; for(int index = 0; index < number_used - 1; index++) {//Place the correct value in a[index]: index_of_next_smallest = index_of_smallest(a, index, number_used); swap_values(a[index], a[index_of_next_smallest]); //a[0] <= a[1] <=...<= a[index] are the smallest of the original array //elements. The rest of the elements are in the remaining positions. } }