Question: Explain what, if anything, is wrong with the following code A. The code is designed to print to the console a chain of nodes that

Explain what, if anything, is wrong with the following code A. The code is designed to print to the console a chain of nodes that begins with firstNode.

Node currentNode = firstNode;

while(currentNode.next!=null) {

System.out.println(currentNode.data);

currentNode = currentNode.next;

}

Explain what, if anything, is wrong with the following code B. The code is designed to double the data stored in a chain of nodes that begins with firstNode.

Node currentNode = firstNode;

while(currentNode!=null) {

currentNode.data = currentNode.data * 2;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!