int[] a = {5, 2, 8, 1, 9};
for (int i = 0; i < a.length - 1; i++) {
int min = i;
for (int j = i + 1; j < a.length; j++) {
if (a[j] < a[min]) min = j;
}
int t = a[i]; a[i] = a[min]; a[min] = t;
}What is the array after the i=1 iteration completes?
- Acheck_circle
{1, 2, 8, 5, 9}
- B
{1, 2, 8, 9, 5}
- C
{1, 5, 2, 8, 9}
- D
{1, 2, 5, 8, 9}
Explanation
From {1,2,8,5,9}, the minimum of the remaining suffix is 2 at index 1, no real swap occurs.