Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started