DEV Community

Dhanashree Rugi
Dhanashree Rugi

Posted on • Edited on

Types of Linked List

There are various types of linked list as follows:

  1. Singly Linked List
  2. Doubly linked List
  3. Circular Linked List
  4. Doubly Circular Linked List

Singly Linked List :

Singly linked list is a most common type of linked list in which each node consists of two parts :

  1. Information or data part
  2. Pointer to the next node.

If suppose the singly linked list consists of four(4) nodes then it is represented as,

image

In this type of linked list, each node contains a single pointer to the next node hence it is called as singly linked list.

Only forward sequential traversal is possible in singly linked list because pointer points to the next node in sequence.

C code for a node in the singly linked list is as follows ,

struct node
{
  int data;
  struct node *next;
}
Enter fullscreen mode Exit fullscreen mode

Doubly Linked List :

In this type of linked list, each node contains two pointers i.e., one points to the next node in sequence and the other points to the immediate previous node.

A node in doubly linked list contains three information,

  1. Data information
  2. Pointer to the next node
  3. Pointer to the previous node

If suppose, the doubly linked list contains four nodes, then it is represented as,
image

First node has no previous node hence the pointer to the previous node is NULL.

Both forward and reverse sequential traverse is possible in doubly linked list.

C code for a node in the doubly linked list is represented as follows,

struct node
{
  int data;
  struct node *next;
  struct node *prev;
}
Enter fullscreen mode Exit fullscreen mode

Circular Linked List :

In circular linked list, the last node's pointer points to the first or head node in the list making it a circular path as shown below.
image

Doubly Circular Linked List :

A node in doubly circular linked list contains three information i.e.,

  1. Data information
  2. Pointer to the next node
  3. Pointer to previous node

The last node's pointer points to first or the head node and the first node's pointer points to the last node in the list making it a circular path.

image

I own a website www.coderlogs.com where in I write similar blogs so do visit this website for more such blog posts.

Top comments (0)