Skip to main content

Part 2 - Types of Linked List

Types of Linked Lists

Based on the structure of linked lists, they can be classified into several types:

  • Singly Linked List

  • Doubly Linked List

  • Circular Linked List

1. Singly Linked List

The singly linked list is the simplest form of linked list, where each node contains two members: data and a next pointer that stores the address of the next node. Each node in a singly linked list is connected through the next pointer, and the next pointer of the last node points to NULL, denoting the end of the list.

Singly Linked List Representation

A singly linked list can be represented as a pointer to the first node, where each node contains:

  • Data: Actual information stored in the node.

  • Next: Pointer to the next node.

// Structure to represent the singly linked list
struct Node {
    int data;       // Data field
    struct Node* next; // Pointer to the next node
};

2. Doubly Linked List

The doubly linked list is a modified version of the singly linked list. Each node contains three members: data, next, and prev. The prev pointer stores the address of the previous node. Nodes are connected via both next and prev pointers. The prev pointer of the first node and the next pointer of the last node point to NULL.

Doubly Linked List Representation

Each node contains:

  • Data: Actual information stored.

  • Next: Pointer to the next node.

  • Prev: Pointer to the previous node.

// Structure to represent the doubly linked list
struct Node {
    int data;       // Data field
    struct Node* next; // Pointer to the next node
    struct Node* prev; // Pointer to the previous node
};

3. Circular Linked List

A circular linked list is similar to a singly linked list, except the next pointer of the last node points to theĀ first node instead of NULL. This circular nature is useful in applications like media players.

Circular Linked List Representation

Each node contains:

  • Data: Actual information stored.

  • Next: Pointer to the next node; the last node points to the first node.

// Structure to represent the circular linked list
struct Node {
    int data;       // Data field
    struct Node* next; // Pointer to the next node
};