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
Get step-by-step solutions from verified subject matter experts
