Question: Given the below code /** The IntInsertionSorter class provides a public static method for performing an insertion sort on an int array. */ public class

Given the below code /** The IntInsertionSorter class provides a public static method for performing an insertion sort on an int array. */ public class IntInsertionSorter { /** The insertionSort method performs an insertion sort on an int array. The array is sorted in ascending order. @param array The array to sort. */ public static void insertionSort(int[] array) { int unsortedValue; // The first unsorted value int scan; // Used to scan the array // The outer loop steps the index variable through // each subscript in the array, starting at 1. The portion of // the array containing element 0 by itself is already sorted. for (int index = 1; index < array.length; index++) { // The first element outside the sorted portion is // array[index]. Store the value of this element // in unsortedValue. /* intermediate results */ System.out.println(" Sorted order for iteration index: "+ index); for (int element : array) System.out.print(element + " "); System.out.println(); unsortedValue = array[index]; // Start scan at the subscript of the first element // outside the sorted part. scan = index; // Move the first element in the still unsorted part // into its proper position within the sorted part. while (scan > 0 && array[scan-1] > unsortedValue) { array[scan] = array[scan - 1]; scan--; } // Insert the unsorted value in its proper position // within the sorted subset. array[scan] = unsortedValue; } } } What would be the array values at each iteration of the sort if the original array was {17, 12, 4, 32, 8, 19} ?

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!