Question
1. We developed Java code for traversing a linked list. Here are several alternate, possibly lawed, approaches for using a traversal to print the contents
1. 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started