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
BoldItalicUnderline
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
