Limited access

Upgrade to access all content for this subject

A programmer has attempted to code an insertion sort algorithm as follows.

public static void sorter( double[] nums)
     for (int i=1; i < nums.length; i++)
          int curr = (int) nums[i];
          int j=i;
          while(j >0 && curr < nums[j-1])
               nums[j] = nums[j-1];
          nums[j] = nums[curr];

However, it is not quite working. What needs to be changed to make this a successful insertion sort algorithm?

I. Change the while statement as follows:

while(j>0 && curr < nums[j])

II. Change the declaration of variable curr as follows:

double curr = nums[i];

III. Change the last statement in the for loop as follows:

nums[j] = curr;

I only.


II only.


III only.


I and II only.


II and III only.

Select an assignment template