Activity: Traversing the Linked List

Scenario

We have a linked list containing some elements and we need to build a string of the form [3,6,4,2,4]. If the list is empty, it should output [].

Aim

To write code in Java for traversing the linked list. 

Steps for Completion

  1. Write a toString() method in the LinkedList class as follows:
public String toString() {
}
  1. Use a while loop to traverse the linked list.

In this section, we have seen how we can implement the various operations found in the linked list. The data structure will be a base tool that we will use to model queues and stacks. Linked lists will also be extensively used in more advanced algorithms further along the book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset