Question: Questions 1 - 3 refer to the following program which correctly sorts the elements of nums into ascending order : public void setup ( )

Questions 1-3 refer to the following program which correctly sorts the elements of nums into ascending
order :
public void setup(){
int [] nums ={3,-1,2,5,-3};
mysterySort(nums);
for (int i : nums)
System.out.print(i+",");
}
public static void mysterySort(int[] items){
for (int outer =1; outer < items.length; outer++)
{
int position = outer;
int k = items[position];
// Shift larger values to the right
while (position >0 && items[position -1]> k)
{
items[position]= items[position -1];
position--;
}
items[position]= k;
/* end of for loop */
}
}
1. The sorting algorithm implemented in the sort method can be best described as (select one by completely
filling in the circle in front of your choice):
o Selection sort
o Insertion sort
o Bubble sort

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 Programming Questions!