Java The next set of questions list code and ask you to describe the contents of
ID: 3890703 • Letter: J
Question
Java
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.
To write the contents of the chain, use the method of connecting the data with arrows, starting with the data contained in firstNode. For example: 4 -> 5 -> 8 -> 3
Part 1:
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.next;
- What is the contents of the chain headed by firstNode?
- What is the data held in the node referred to by currentNode?
Part 2:
Node a = new Node(5);
Node b = new Node(3, a);
Node c = new Node(7, b);
Node firstNode = new Node(2, c);
Node current = firstNode;
current.next.next.data = 8;
- What is the contents of the chain headed by firstNode?
- What is the data held in the node referred to by current?
Part 3:
Flag this Question
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.data = 15;
- What is the contents of the chain headed by firstNode?
- What is the data held in the node referred to by currentNode?
Part 4:
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);
- What is the result of the println?
Part 5:
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);
- What is the result of the println?
Explanation / Answer
Part 1:
Chain from firstNode : 2 -> 7 -> 3 -> 5
currentNode->data : 7
Part 2:
Chain from firstNode : 2 -> 7 -> 8 -> 5
currentNode->data : 2
Part 3:
Chain from firstNode : 15 -> 7 -> 3 -> 5
currentNode->data : 15
Part 4:
currentNode->next : null
Part 5:
currentNode->next->data : null
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.