The insertionSort method in the IntInsertionSorter class presented in this chapt
ID: 3652026 • Letter: T
Question
The insertionSort method in the IntInsertionSorter class presented in this chapter sorts an array of int values. Create an ObjectInsertionSorter class that can sort Comparable objects. Demonstrate the class in a program that sorts an array of String objects.
public class IntInsertionSorter
{
public static void insertionSort(int[] array)
{
int unsortedValue;
int scan;
for (int index = 1; index, array.length; index++)
{
unsortedValue = array[index];
scan = index;
while (scan > 0 && array[scan - 1] > unsortedValue)
{
array[scan] = array[scan-1];
scan--;
}
array[scan] = unsortedValue;
}
}
}
From Starting Out With Java From Control Structures through Data Structures, 2nd Edition by Tony Gaddis