Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

/** * Recursive method to compare two Strings using alphabetical * order as the natural order (case insensitive). * @param String s1 to compare * @param String s2 to compare * @return an integer with the following convention: * if s1 comes before s2 then it returns -1 * if s1 == (or indistinguisable from) s2 then it returns 0 * if s1 comes after s2 then it returns 1 */ public static int compareTo(String s1, String s2, int index) { if(s1.length() == index && s2.length() == index) { return 0; } if(s1.length() == index && s2.length() > index) { return -1; }

if(s1.length() > index && s2.length() == 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,index+1);

} //end recursive method compareTo

Note: Can you include comments for some of the line of code so that I can understand what is going on with the method written?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

Outline the employee's role in the succession management process.

Answered: 1 week ago