2. Use the Java code below to draw the diagram and show the output. NOTE: For th
ID: 3685609 • Letter: 2
Question
2. Use the Java code below to draw the diagram and show the output. NOTE: For this exercise, each node has the usual 2 components (info-link).
LinkedListNode current = new LinkedListNode();
current.info = 10;
LinkedListNode node = new LinkedListNode();
node.info = 27;
node.link = null;
current.link = node;
node = new LinkedListNode();
node.info = 20;
node.link = current.link;
current.link = node;
System.out.println(current.info + " " + node.info);
node = node.link;
System.out.println(node.info);
3. Use the Java code below to draw the diagram and show the output. NOTE: For this exercise, each node has the usual 2 components (info-link).
LinkedListNode current = new LinkedListNode();
current.info = 10;
LinkedListNode node = new LinkedListNode();
node.info = 27;
node.link = null;
current.link = node;
node = new LinkedListNode();
node.info = 20;
node.link = current;
current = node;
node = new LinkedListNode();
node.info = 37;
node.link = current.link;
current.link = node;
node = current;
while(node != null) {
System.out.println(node.info + " ");
node = node.link;
}
Explanation / Answer
Answer 1)
10 20
27
Answer 2)
20
37
10
27
EXPLANATION
Answer 1:
current.link = node;
Diagram: current [10] -> node [20] -> [27]
System.out.println(current.info + " " + node.info); //hence output is 10 20
node = node.link;
Diagram: current [10] -> [20] -> node[27]
System.out.println(node.info); //hence output is 27
Answer 2
Diagram: node/current -> [20] -> [37]->[10] -> [27]
initially node is at 20.
while(node != null) {
System.out.println(node.info + " ");
node = node.link;
}
is a traversal through link list. Hence output is 20 37 10 27
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.