public class StringNode { private char ch; private StringNode next; /** * Constr
ID: 3631392 • Letter: P
Question
public class StringNode {
private char ch;
private StringNode next;
/**
* Constructor
*/
public StringNode(char c, StringNode n) {
ch = c;
next = n;
}
/**
public static char largestChar(StringNode str)
This method should use recursion to find and return the character with the
largest character code in the string specified by str. You should make use of
the fact that characters can be compared using the standard relational
operators; in particular, the char ch1 is larger than the char ch2 if
ch1 > ch2. For example, given the linked list created in part a,
largestChar(str) should return 't', because it has the largest character
code among the characters in "method frame". If null is passed in as the
parameter, the method should return the character '' (a backslash followed
by a zero), which has the smallest character code of any character.
Explanation / Answer
//StringNode.java public class StringNode { public char ch; public StringNode next; /** * Constructor */ public StringNode(char c, StringNode n) { ch = c; next = n; } } //LargestCharRecursion.java public class LargestCharRecursion { public static void main(String[] args) { String input="method frame"; //Creating Linked List StringNode listHead=null; StringNode list=null; for(int i=0;i nextNode.ch) { str.next = nextNode.next; ch=largestChar(str); } else if(str.chRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.