Question 1 of 10
Harbor buoys store depth readings in meters. selectionSort takes the smallest remaining value and swaps it into the next left slot. What are the contents of depths after the first outer-loop pass?
public static void selectionSort(int[] data)
{
for (int i = 0; i < data.length - 1; i++)
{
int minIndex = i;
for (int j = i + 1; j < data.length; j++)
{
if (data[j] < data[minIndex])
{
minIndex = j;
}
}
int temp = data[i];
data[i] = data[minIndex];
data[minIndex] = temp;
}
}
int[] depths = {8, 3, 6, 1, 4};
selectionSort(depths);
- A. {1, 3, 6, 8, 4}
- B. {1, 3, 4, 6, 8}
- C. {3, 6, 8, 1, 4}
- D. {8, 3, 6, 4, 1}