Question
Java/LinkedList Need help with a few of the TODO parts, more info below in comments in bold. Thanks, package lab4; import java.util.IdentityHashMap; public class IntNode
Java/LinkedList Need help with a few of the TODO parts, more info below in comments in bold.
Thanks,
package lab4;
import java.util.IdentityHashMap;
public class IntNode implements Cloneable { private int data; private IntNode next; public IntNode(int d, IntNode n) { data = d; next = n; } public IntNode getNext() { return next; } /// Override methods from Object @Override public boolean equals(Object obj) { throw new UnsupportedOperationException("Don't use .equals to compare nodes!"); } @Override public IntNode clone() { try { return (IntNode)super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError("IntNodes should be cloneable!"); } } protected String originalToString() { return super.toString(); } @Override public String toString() { String nextString = "null"; if (next != null) nextString = next.originalToString(); return super.toString() + "(" + data + "." + nextString + ")"; } /// Print method that is used for testing /** * Convert a list to a string for debugging purposes. * The string is of the form [n1, n2, n3, ...]. * if the list ends in a cycle then we have "..." followed by * the one-based index of the node we go back to. * @param head list t print, may be null * @return string representation of the whole list. */ public static String listToString(IntNode head) { if (head == null) return "[]"; IdentityHashMap
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started