//DISPLAY 17.3 Using a Generic Sorting Function //Demonstrates a generic sorting function. #include using namespace std; //The file sortfunc.cpp defines the following function: //template //void sort(BaseType a[], int numberUsed); //Precondition: numberUsed <= declared size of the array a. //The array elements a[0] through a[numberUsed - 1] have values. //Postcondition: The values of a[0] through a[numberUsed - 1] have //been rearranged so that a[0] <= a[1] <= ... <= a[numberUsed - 1]. #include "sortfunc.cpp" int main( ) { int i; int a[10] = {9, 8, 7, 6, 5, 1, 2, 3, 0, 4}; cout << "Unsorted integers:\n"; for (i = 0; i < 10; i++) cout << a[i] << " "; cout << endl; sort(a, 10); cout << "In sorted order the integers are:\n"; for (i = 0; i < 10; i++) cout << a[i] << " "; cout << endl; double b[5] = {5.5, 4.4, 1.1, 3.3, 2.2}; cout << "Unsorted doubles:\n"; for (i = 0; i < 5; i++) cout << b[i] << " "; cout << endl; sort(b, 5); cout << "In sorted order the doubles are:\n"; for (i = 0; i < 5; i++) cout << b[i] << " "; cout << endl; char c[7] = {'G', 'E', 'N', 'E', 'R', 'I', 'C'}; cout << "Unsorted characters:\n"; for (i = 0; i < 7; i++) cout << c[i] << " "; cout << endl; sort(c, 7); cout << "In sorted order the characters are:\n"; for (i = 0; i < 7; i++) cout << c[i] << " "; cout << endl; return 0; }