Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class StringNode { private char ch; private StringNode next; /** * Constr

ID: 3631393 • Letter: P

Question

public class StringNode {

    private char ch;

    private StringNode next;

    /**

     * Constructor

     */

    public StringNode(char c, StringNode n) {

        ch = c;

        next = n;

    }

/**

* compareAlpha - compares two linked-list strings to determine

* which comes first alphabetically (i.e., according to the ordering

* used for words in a dictionary).

*

* It returns:

* 1 if str1 comes first alphabetically

* 2 if str2 comes first alphabetically

* 0 if str1 and str2 represent the same string

*

* The empty string comes before any non-empty string,

* and the prefix of a string comes before the string

* itself (e.g., "be" comes before "become").

*/

compareAlpha()//must write iteration way

concat() returns the concatenation of two linked-list strings// write iteration version

Explanation / Answer

//StringNode .java public class StringNode { public char ch; public StringNode next; /** * Constructor */ public StringNode(char c, StringNode n) { ch = c; next = n; } } // public class LargestCharRecursion { public static void main(String[] args) { StringNode list1=convertToList("".toLowerCase()); StringNode list2=convertToList("".toLowerCase()); int nRes= compareAlpha(list1, list2); System.out.println(nRes); } private static StringNode convertToList(String input) { StringNode listHead=null; StringNode list=null; for(int i=0;i length1) { for(int charIndex=0;charIndex str2.ch) return 2; else if(str1.ch