Question: Write a recursive method that uses your compareTo(String, String) method to find the minimum (i.e. first by alphabetical order) String in an array of Strings,

Write a recursive method that uses your compareTo(String, String) method to find the minimum (i.e. first by alphabetical order) String in an array of Strings, given the array and the number of strings in the array.

public static String findMinimum(ArrayList stringArray)

Hint: Use the above method signature to call a private, helper method that is recursive - you can add more parameters to this helper method!

// This is the recursive compareTo(String, String) method mentioned above public static int compareTo(String s1, String s2, int len1, int len2, int index) {

if(len1 == index && len2 == index) { return 0; } if(len1 == index && len2 > index) { return -1; }

if(len1 > index && len2 == index) { return 1; }

if(s1.charAt(index)< s2.charAt(index)) { return -1; }

else if(s1.charAt(index)> s2.charAt(index)) { return 1;

}

return compareTo(s1,s2,len1,len2,index+1);

} //end recursive method compareTo

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!