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

and change int array[] to t array[] but I can make it work

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!