The next set of questions list code and ask you to describe the contents of the
ID: 3727082 • Letter: T
Question
The next set of questions list code and ask you to describe the contents of the chain headed by firstNode and the value of the node referred to be currentNode. Please also explain why.
Question 1. What is the contents of the chain headed by firstNode?
F. 2
Question 2. What is the data held in the node referred to by currentNode?
E. 7
Node a = new Node(5);
Node b = new Node(3, a);
Node c = new Node(7, b);
Node firstNode = new Node(2, c);
Node currentNode = firstNode;
currentNode.next = currentNode.next.next;
Question 3. What is the contents of the chain headed by firstNode?
J. 2->5
Question 4. What is the data held in the node referred to by currentNode?
E. 7
Node a = new Node(5);
Node b = new Node(3, a);
Node firstNode = new Node(2,b);
Node currentNode = firstNode;
currentNode = currentNode.next;
currentNode = currentNode.next;
System.out.println(currentNode.next);
Question 5. What is the result of the println?
6.A 5 is printed
Node a = new Node(5);
Node b = new Node(3, a);
Node firstNode = new Node(2,b);
Node currentNode = firstNode;
currentNode = currentNode.next;
currentNode = currentNode.next;
System.out.println(currentNode.next.data);
Question 6. What is the result of the println?
A. none of these is correctExplanation / Answer
Node a = new Node(5);
Node b = new Node(3, a);
Node c = new Node(7, b);
Node firstNode = new Node(2, c);
Node currentNode = firstNode;
firstNode => 2 -> 7 -> 3-> 5 -> NULL
currentNode => firstNode
Question 3. What is the contents of the chain headed by firstNode?
Ans: G. 2->7->3->5
Q4. What is the data held in the node referred to by currentNode?
Ans: C. 2
####################
Node a = new Node(5);
Node b = new Node(3, a);
Node firstNode = new Node(2,b);
Node currentNode = firstNode;
currentNode = currentNode.next;
currentNode = currentNode.next;
System.out.println(currentNode.next);
firstNode => 2 -> 3 -> 5 -> null
currentNode => 5 -> null
Question 5. What is the result of the println?
Ans: A null is printed (because next of 5 is null)
######################
Node a = new Node(5);
Node b = new Node(3, a);
Node firstNode = new Node(2,b);
Node currentNode = firstNode;
currentNode = currentNode.next;
currentNode = currentNode.next;
System.out.println(currentNode.next.data);
firstNode => 2 -> 3 -> 5 -> null
currentNode => 5 -> null
Ans: 1. An error is thrown
because next of 5 is null so, null.data throw an error
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.