Question: Java: Given the following code for selection sort, give the values for the array for each pass of the algorithm for the array { 5,

Java: Given the following code for selection sort, give the values for the array for each pass of the algorithm for the array { 5, 15, 7, 4, 8, 18} .

public static void selectionSort(int[] array) {

int startScan, index, minIndex, minValue; for (startScan = 0; startScan < (array.length-1); startScan++)

{

minIndex = startScan;

minValue = array[startScan];

for(index = startScan + 1; index < array.length; index++) {

if (array[index] < minValue) {

minValue = array[index];

minIndex = index;

}

}

array[minIndex] = array[startScan];

array[startScan] = minValue;

}

}

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!