Question: void selection(int a[], int n) { for (int j = 0; j < n - 1; j++){ int min_index = j; for (int i =

void selection(int a[], int n) {

for (int j = 0; j < n - 1; j++){

int min_index = j;

for (int i = j + 1; i < n; i++) {

if (a[i] < a[min_index]) {

min_index = i;

}

}

swap(a[j], a[min_index]);

}

}

Using C++. Update the function above to show the number of comparisons and number of swaps for each pass.

int sample [] ={10, 7, 9, 5, 1};

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!