Question: We developed Java code for traversing a linked list. Here are several alternate, possibly lawed, approaches for using a traversal to print the contents of
We developed Java code for traversing a linked list. Here are several alternate, possibly lawed, approaches for using a traversal to print the contents of the linked list of strings accessed through letters. Critique each of them:
a. LLNode currNode = letters;
while (currNode != null)
{
System.out.println(currNode.getInfo());
currNode = currNode.getLink();
}
b. LLNode currNode = letters;
while (currNode != null)
{
currNode = currNode.getLink();
System.out.println(currNode.getInfo());
}
c. LLNode currNode = letters;
while (currNode != null)
{
System.out.println(currNode.getInfo());
if (currNode.getLink() != null)
currNode = currNode.getLink();
else
currNode = null; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
