Flat Preloader Icon

Types of Linked List

  • In Java, linked lists are data structures where each element is a separate object that contains a data element and a reference (link) to the next element in the sequence. There are several types of linked lists, each with its own characteristics and use cases. The main types of linked lists include:

The Following Are The Types Of Linked List

1. Singly Linked List

  • A singly linked list is a type of linked list where each node in the list points to the next node in the sequence. The last node points to null, indicating the end of the list. Singly linked lists are relatively simple and can be implemented efficiently. However, they do not support backward traversal.
  • Here is a simple implementation of a singly linked list in Java:

Representation Of The Node In A Singly Linked List

				
					struct node  
{  
   int data;  
   struct node *next;  
}
				
			
  • In the above representation, we have defined a user-defined structure named a node containing two members, the first one is data of integer type, and the other one is the pointer (next) of the node type.

2. Doubly Linked List

  • A doubly linked list is a type of linked list where each node maintains a reference to both the next node and the previous node in the sequence. This feature allows for both forward and backward traversal of the list. The first node’s previous reference and the last node’s next reference point to null
  • Below is an example implementation of a doubly linked list in Java:

Representation Of The Node In A Doubly Linked List

				
					struct node  
{  
  int data;  
  struct node *next;  
 struct node *prev;   
}   
				
			
  • In the above representation, we have defined a user-defined structure named a node with three members, one is data of integer type, and the other two are the pointers, i.e., next and prev of the node type. The next pointer variable holds the address of the next node, and the prev pointer holds the address of the previous node. The type of both the pointers, i.e., next and prev is struct node as both the pointers are storing the address of the node of the struct node type.

3. Circular Linked List

  • A circular linked list is a type of linked list where the last node points back to the first node, forming a circular structure. This circular linking ensures that there is no end to the list, and the traversal can continue indefinitely.
  • Here’s an example implementation of a circular linked list in Java:

Representation Of The Node In A Circular Linked List

				
					struct node  
{  
   int data;  
   struct node *next;  
}  
				
			
  • A circular linked list is a sequence of elements in which each node has a link to the next node, and the last node is having a link to the first node.

4. Doubly Circular Linked List

  • A doubly circular linked list is a type of linked list in which each node has references to both the next and previous nodes, and the last node points back to the first node, forming a circular structure in both directions.
  • Below is an example implementation of a doubly circular linked list in Java:

Representation Of The Node In A Doubly Circular Linked List

				
					struct node  
{  
  int data;  
  struct node *next;  
 struct node *prev;   
}  
				
			
  • In this implementation, the Node class represents the individual nodes in the doubly circular linked list. The DoublyCircularLinkedList class contains methods for inserting elements into the list and displaying the elements. The insert method inserts a new node at the end of the list, and the display method prints the elements of the circular list.