Question: Consider the insertion sort function definition given in chapter 16, page 1064. void insertionSort (int list[], int listLength) { int firstOutOfOrder, location; int temp; for
Consider the insertion sort function definition given in chapter 16, page 1064.
void insertionSort (int list[], int listLength) { int firstOutOfOrder, location; int temp;
for (firstOutOfOrder = 1; firstOutOfOrder < listLength; firstOutOfOrder++) { if (list[firstOutOfOrder] < list[firstOutOfOrder 1] { temp = list[firstOutOfOrder]; location = firstOutOfOrder;
do { list[location] = list[location 1]; location--; } while (location > 0 && list[location -1] > temp);
list[location] = temp; } //end if } //end for-loop } //end insertionSort
1. Re-write this insertionSort function into a template function.
2. Assume statement double dList [50]; declares an array of 50 doubles, and dList is properly initialized. Write statement to call template function you defined in (a) to sort the array.
3. To use the template function defined in (a) to sort an array of class objects, the class must define (i.e., overload) what operator so the template function would work properly?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
