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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started