Question: The Insertion Sort method below is used to sort arrays of ints in ascending order. Modify the function to sort Strings in descending order. Remember,

The Insertion Sort method below is used to sort arrays of ints in ascending order. Modify the function to sort Strings in descending order. Remember, strings can be compared using the compareTo method.

str1.compareTo(str2) will return a negative value when str1 would come before str2 alphabetically, a positive value when str1 comes after str2 alphabetically, and zero when the strings are equal.

public static void insertionSort(int[] data) { for (int i=1; i =0 && data[j] > temp) { data[j+i] = data[j]; j--; } data[j+1] = temp; } }

BoldItalicUnderline

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!