Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following method sorts an array of doubles. public void sort(double[] list)

ID: 3643436 • Letter: T

Question

The following method sorts an array of doubles.

public void sort(double[] list)
{
for(int start = 1; start < list.length; start++)
{
double temp = list[start];
int k = start;
while(k > 0 && list[k-1] > temp)
{
list[k] = list[k-1];
k++;
}
list[k] = temp;
}
}

Assume the String array values is initialized as shown below.

values | 5.0 | 1.0 | 3.0 | 8.0 | 4.0 | 6.0 | 2.0 |

Which of the following best represents the array word after the fourth pass through the outer loop in the call sort(values)?

A.) | 1.0 | 2.0 | 3.0 | 4.0 | 8.0 | 6.0 | 5.0 |
B.) | 1.0 | 2.0 | 3.0 | 4.0 | 5.0 | 8.0 | 6.0 |
C.) | 1.0 | 3.0 | 5.0 | 8.0 | 4.0 | 6.0 | 2.0 |
D.) | 1.0 | 3.0 | 4.0 | 5.0 | 8.0 | 6.0 | 2.0 |
E.) | 2.0 | 1.0 | 3.0 | 4.0 | 5.0 | 6.0 | 8.0 |

Explanation / Answer

A. 1.0,2.0,3.0,4.0,8.0,6.0,5.0