Question: this is a c++ program we need to change this code so it works with an array of any data type. I know that we
this is a c++ program
we need to change this code so it works with an array of any data type. I know that we need to use at the to templated
void sort(int array[], int N) { int lrgIndx; //the index of the largest value
int temp; //temporary variable that holds the largest value
//last is the last index in unsorted portion
for(int last = N-1; last >= 1; last--) { lrgIndx = 0; //assume the first item is the largest
//find the largest in unsorted portion ([0..last])
for(int i = 1; i <= last; i++) { if(array[i] > array[lrgIndx]) //The current item is larger
lrgIndx = i; }
//swap the largest with the last item in the unsorted portion
temp = array[lrgIndx]; array[lrgIndx] = array[last]; array[last] = temp; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
