Write a method that clones a sequence/linked list. The feilds of the Seq class a
ID: 3795249 • Letter: W
Question
Write a method that clones a sequence/linked list. The feilds of the Seq class are...
private Node head;
private int manyNodes; // how many nodes are in the linked list
private Node precursor; // node before cursor
private Node cursor;
private Node tail;
The constructor for the nodes looks like this...
private Node(Cup data, Node next) {
this.data = data;
this.next = next;
}
Finish the method below
public Seq clone() {
Seq result; // the copied linked list to be returned
try {
result = (Seq) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("This class does not implement Cloneable");
}
// TODO do cloning part here
return result;
}
Explanation / Answer
public static CharNode listPosition(CharNode head, int position) { CharNode cursor; int i; if (positionRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.