The following class LinkedNode representing a node. If the variable list represe
ID: 3827166 • Letter: T
Question
The following class LinkedNode representing a node. If the variable list represents a linked list of these nodes, which of the statement that follows the class definition will traverse that the data in the list? Class LinkedNode {int data; LinkedNode next; LinkedNode(int) {data = i; next = null;}} I public void print(LinkedNode list() {LinkedNode current = list; while (current next! = null) {System.out.println(current data); current = current.next;}} II public void print(LinkedNode list) {LinkedNode current = list; while (current! = null) {System.out.println(current next); {System.out.println(current.next); current = current.next;}} III public void print(LinkedNode list) {LinkedNode current = list; while (current! = null) {System.out.println(current.data); current = current.next;}} IV public void print(LinkedNode list) {LinkedNode current = list; while(current! = null) {System.out.println(current.data); current++;}}Explanation / Answer
1.The Given First Code will only Print Two values as it is checking for next value
to null itself in while loop.
2.The Given Second Code will print pointer values so it will not print the Data values.
3.The Given Third Code will Print The Correct Output of 3 Data values stored in
Linked Node.
public void print(LinkedNode list)
{
LinkedNode current=list;
while(current!=null)
{
System.out.println(current.data);
current=current.next;
}
}
4.The Given Fourth Code will print null or garbage values. As current is
incremented not pointed to next value.
Hope Your queries solved. if any please let me know.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.