Question: The following incomplete method is intended to sort its array paramter arr in increasing order. //postcondition: arr is sorted in increasing order public static void

 The following incomplete method is intended to sort its array paramter

The following incomplete method is intended to sort its array paramter arr in increasing order.

//postcondition: arr is sorted in increasing order public static void sortArray(int[] arr) { int j, k;

for (j = arr.length - 1; j > 0; j--) { int pos = j;

for ( /* missing code */) { if (arr[k] > arr[pos]) { pos = k; } } swap (arr, j, pos); } }

Assume that swap (arr, j, pos) exchanges the values of arr[j] and arr[pos]. Which of the following could be used to replace /* missing code */ so that executing the code segment sorts the values in array arr?

Question 17 options:

A)

k = 1; k > arr.length; k++

B)

k = 1; k

C)

k = j - 1; k >= 0; k--

D)

k = j - 1; k > 0; k--

E)

k = 0; k

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!