public class StringNode { private char ch; private StringNode next; /** * Constr
ID: 3631983 • Letter: P
Question
public class StringNode {
private char ch;
private StringNode next;
/**
* Constructor
*/
public StringNode(char c, StringNode n) {
ch = c;
next = n;
}
/**
* concat recursive method - returns the concatenation of two linked-list strings
*/
public static StringNode concat(StringNode str1, StringNode str2) {
StringNode cat;
if (str1 == null)
cat = copy(str2);
else
cat = new StringNode(str1.ch, concat(str1.next, str2));
return cat;
}
public static StringNode copy(StringNode str)
{
StringNode output = new StringNode(str.ch, null);
str = str.next;
StringNode curr = output;
while(str != null)
{
curr.next = new StringNode(str.ch, null);
curr = curr.next;
str = str.next;
}
return output;
}
I give you recursive version of concat method.Make it iteration version.
Explanation / Answer
import java.io.*;
import java.util.*;
public class StringNode
{
private char ch;
private StringNode next;
public StringNode(char c, StringNode n)
{
ch = c;
next = n;
}
private static StringNode getNode(StringNode str, int i)
{
StringNode curr = str;
int x = 0;
while (curr != null)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.