Suppose that p, q, and r are all references to nodes in a linked list with 15 no
ID: 3644749 • Letter: S
Question
Suppose that p, q, and r are all references to nodes in a linked list with 15 nodes. The variable p refers to the first node, q refers to the 8th node, and r refers to the last node. Write a few lines of code that will make a new copy of the list. You code should set THREE new variables called x, y, and z so that: x refers to the first node of the copy, y refers to the 8th node of the copy, and z refers to the last node of the copy. Your code may NOT contain any loops, but it can use the other IntNode methods.Explanation / Answer
Node clone(Node root){
if (root==null) return null;
Node result=new Node();
if(root==p) x=result;
else if(root==q) y=result;
else if(root==r) z=result;
result.setvalue(getValue(root));
result.setLink(clone(getLink(root));
return result;
}
Before calling this function, be sure to initialise the objects Node x,y,z;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.