Skip to content
Advertisement

javascript – simple linked list traversal issue

I have implemented a single linked list using javascript. Please find the code below:

JavaScript

But the traverse method never prints the last element. What am I missing here? The insertAtTail method looks correct though. Could anyone please let me know.

thanks

Advertisement

Answer

In the traverse, you need to check all nodes not until the next one is null.

so I just removed the .nextElement from the traverse and it works fine

JavaScript
Advertisement