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
Explanation / Answer
//ObjectInsertionSorter class public class ObjectInsertionSorter { public static void insertionSort(Object[] a) { for (int i=0; i = 0; j--) { if (((Comparable)a[j]).compareTo(v)Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.