Linked List in Data Structure

What is a Linked List?

A linked list is a fundamental data structure in computer science used to store a collection of elements (called nodes) in a linear order. Unlike arrays, linked lists do not store elements in contiguous memory locations; instead, each node contains the data and a reference (or pointer) to the next node in the sequence. This allows for dynamic memory allocation and efficient insertion and deletion of elements.

Diagram of Linked List :-

What is Memory Allocation ?

Memory allocation refers to the process by which a computer program reserves memory space in RAM for storing data during execution. It is a crucial concept in programming, especially when dealing with data structures like arrays, linked lists, or trees.

1. Static Memory Allocation

Memory size is determined at compile time.
Typically used for arrays or fixed-size variables.
Memory is allocated in the stack segment of RAM.
Cannot change the size during program execution.

2. Dynamic Memory Allocation

Memory is allocated at runtime, as needed.
Usually used for linked lists, trees, graphs, or large arrays.
Memory is allocated in the heap segment of RAM.
Provides flexibility to grow or shrink memory usage during program execution.
Terminologies of Linked List:-

    • Head: Indicates the starting of linked list. Head points to the first node of the linked list 
    • Node: Each record of a linked list. A linked list consists of a data element known as a node. 
    • Address: It stores the particular memory location/ address of the node 
    • Pointer: It stores the address of variable. 
    • Information/Data field: It holds the actual value or data associated with the node. 
    • Next Pointer: It stores the memory address (reference) of the next node in the sequence. 
    • Null Pointer/ Tail: Indicating the end of the list. 
    • Empty List: If there are no nodes in a linked list, it is an empty linked list
Types Of Linked List:

1.Singly Linked List :-
    • It is the simplest type of linked list in which every node contains some data and a pointer to the next node of the same data type. 
    • It is one in which all nodes are connected sequentially to each other. 
    • The linked list, which is shown in the following diagram, is known as a singly linked list as it contains only a single link.  
    • In this list, only forward traversal is possible; we cannot traverse in the backward direction as it has only one link in the list.
 Diagram of singly Linked List :-

Representation of the node in a singly linked list:-

struct node { 
 int data; 
 struct node *next; 
 }   

Operation performed on Singly Linked List :- 

1.Insert element At Beginning :-
  • Allocate memory for new node.
  • Store data .
  • Change next of new node to point to head.  
  • Change head to point to recently created node
CODE : 

#include <stdio.h>
#include <stdlib.h>
struct Node {
    int data;
    struct Node *next;
};
void insertAtStart(struct Node **head, int value) {
    struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = *head;
    *head = newNode;
}
int main() {
    struct Node *head = NULL, *temp;
    int n, i, value;
    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        printf("Enter value: ");
        scanf("%d", &value);

        insertAtStart(&head, value);
    }

    temp = head;
    printf("Linked List: ");
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :



 2.Insert element At Ending :-
  • Allocate memory for new node. 
  • Store data
  • Traverse to last node  
  • Change next of last node to recently created node
CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *newNode;
    int n, i, value;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        newNode = (struct Node*)malloc(sizeof(struct Node));
        printf("Enter value: ");
        scanf("%d", &value);

        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    printf("\nLinked List before insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    newNode = (struct Node*)malloc(sizeof(struct Node));
    printf("\nEnter value to insert at end: ");
    scanf("%d", &value);

    newNode->data = value;
    newNode->next = NULL;

    temp = head;
    while (temp->next != NULL) {
        temp = temp->next;
    }
    temp->next = newNode;

    printf("\nLinked List after insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :

3. Insert element At Middle :-

  • Allocate memory for new node
  • Store data
  • Traverse to the required position
  • Change links
CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *newNode;
    int n, i, value, pos;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        newNode = (struct Node*)malloc(sizeof(struct Node));
        printf("Enter value: ");
        scanf("%d", &value);

        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    printf("\nLinked List before insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    newNode = (struct Node*)malloc(sizeof(struct Node));
    printf("\nEnter value to insert: ");
    scanf("%d", &value);
    printf("Enter position: ");
    scanf("%d", &pos);

    newNode->data = value;

    temp = head;
    for (i = 1; i < pos - 1; i++) {
        temp = temp->next;
    }

    newNode->next = temp->next;
    temp->next = newNode;

    printf("\nLinked List after insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :

4. Delete element At Beginning :-
  • Store head in temp
  • Move head to next node
  • Free temp
CODE : 
#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL;
    int n, i, value;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    printf("\nBefore deletion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    temp = head;
    head = head->next;
    free(temp);

    printf("\nAfter deleting first node:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :


 5.Delete element At Ending :-
  • Traverse to second last node
  • Free last node
  • Set next of second last node to NULL
CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *prev;
    int n, i, value;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    printf("\nBefore deletion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    temp = head;
    while (temp->next != NULL) {
        prev = temp;
        temp = temp->next;
    }

    prev->next = NULL;
    free(temp);

    printf("\nAfter deleting last node:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :


 6.Delete element At Middle :-
  • Traverse to node before position
  • Store node to be deleted
  • Change links
  • Free node
CODE :

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *del;
    int n, i, value, pos;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    printf("\nBefore deletion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    printf("\nEnter position to delete: ");
    scanf("%d", &pos);

    temp = head;
    for (i = 1; i < pos - 1; i++) {
        temp = temp->next;
    }

    del = temp->next;
    temp->next = del->next;
    free(del);

    printf("\nAfter deleting middle node:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :



 7.Searching an Element from the Linked List :-
  • Traverse the list

  • Compare each node data with key

  • If found, print position

CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL;
    int n, i, value, key, pos = 1, found = 0;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    printf("Enter element to search: ");
    scanf("%d", &key);

    temp = head;
    while (temp != NULL) {
        if (temp->data == key) {
            found = 1;
            break;
        }
        pos++;
        temp = temp->next;
    }

    if (found)
        printf("Element found at position %d", pos);
    else
        printf("Element not found");

    return 0;
}

Output  :


 8. Sorting a Linked List :-
  • Traverse list using two loops

  • Compare node data

  • Swap data if required

CODE :

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp, *i, *j;
    int n, value, swap;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (int k = 0; k < n; k++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    for (i = head; i != NULL; i = i->next) {
        for (j = i->next; j != NULL; j = j->next) {
            if (i->data > j->data) {
                swap = i->data;
                i->data = j->data;
                j->data = swap;
            }
        }
    }

    printf("Sorted Linked List:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d -> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :



2.Doubly Linked List :-
  •  A doubly linked list or a two-way linked list is a more complex type of linked list that contains a pointer to the next as well as the previous node in sequence. 
  • Therefore, it contains three parts of data, a pointer to the next node, and a pointer to the previous node. This would enable us to traverse the list in the backward direction as well. Below is the image for the same: 
 Diagram of Doubly Linked List :-


Representation of the node in a Doubly linked list:-

struct node { 
int data; 
struct node *next; 
struct node *prev;
 }   

Operation performed on Doubly Linked List :- 

1.Insert element At Beginning :-
  • Allocate memory for new node
  • Store data
  • Set newNode->prev = NULL
  • Set newNode->next = head
  • Update head->prev
  • Move head to new node
CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev, *next;
};

int main() {
    struct Node *head = NULL, *newNode;
    int n, value;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);

        newNode->data = value;
        newNode->prev = NULL;
        newNode->next = head;

        if (head != NULL)
            head->prev = newNode;

        head = newNode;
    }

    printf("Doubly Linked List:\n");
    while (head != NULL) {
        printf("%d <-> ", head->data);
        head = head->next;
    }
    printf("NULL");
    return 0;
}

Output  :


 2.Insert element At Ending :-
  • Allocate memory for new node.

  • Store data.

  • Traverse to last node.

  • Set next of last node to new node.

  • Set prev of new node to last node.

CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *newNode;
    int n, i, value;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    // Create doubly linked list
    for (i = 0; i < n; i++) {
        newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);

        newNode->data = value;
        newNode->next = NULL;

        if (head == NULL) {
            newNode->prev = NULL;
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            newNode->prev = temp;
            temp = newNode;
        }
    }

    printf("\nDoubly Linked List before insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    // Insert element at end
    newNode = (struct Node*)malloc(sizeof(struct Node));
    printf("\nEnter value to insert at end: ");
    scanf("%d", &value);

    newNode->data = value;
    newNode->next = NULL;

    temp = head;
    while (temp->next != NULL) {
        temp = temp->next;
    }

    temp->next = newNode;
    newNode->prev = temp;

    printf("\nDoubly Linked List after insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :


3. Insert element At Middle :-

  • Allocate memory for new node.

  • Traverse to node before desired position.

  • Update links:

    • newNode->next = temp->next

    • newNode->prev = temp

    • temp->next->prev = newNode (if temp->next != NULL)

    • temp->next = newNode

CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *newNode;
    int n, i, value, pos;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        newNode = (struct Node*)malloc(sizeof(struct Node));
        printf("Enter value: ");
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;
        newNode->prev = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            newNode->prev = temp;
            temp = newNode;
        }
    }

    printf("\nDoubly Linked List before insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    newNode = (struct Node*)malloc(sizeof(struct Node));
    printf("\nEnter value to insert: ");
    scanf("%d", &value);
    printf("Enter position: ");
    scanf("%d", &pos);

    newNode->data = value;

    temp = head;
    for (i = 1; i < pos - 1; i++)
        temp = temp->next;

    newNode->next = temp->next;
    newNode->prev = temp;
    if (temp->next != NULL)
        temp->next->prev = newNode;
    temp->next = newNode;

    printf("\nDoubly Linked List after insertion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :



4. Delete element At Beginning :-
  • Store current head in temp.

  • Move head to next node.

  • Set prev of new head to NULL.

  • Free temp.

CODE :
 
#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL;
    int n, i, value;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;
        newNode->prev = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            newNode->prev = temp;
            temp = newNode;
        }
    }

    printf("\nBefore deletion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    temp = head;
    head = head->next;
    if (head != NULL)
        head->prev = NULL;
    free(temp);

    printf("\nAfter deleting first node:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :



 5.Delete element At Ending :-
  • Traverse to last node.

  • Set next of second last node to NULL.

  • Free last node.

CODE :

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL;
    int n, i, value;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;
        newNode->prev = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            newNode->prev = temp;
            temp = newNode;
        }
    }

    printf("\nBefore deletion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    temp = head;
    while (temp->next != NULL)
        temp = temp->next;

    if (temp->prev != NULL)
        temp->prev->next = NULL;
    else
        head = NULL;

    free(temp);

    printf("\nAfter deleting last node:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :




 6.Delete element At Middle :-
  • Traverse to the node to be deleted.

  • Update next of previous node to point to next node.

  • Update prev of next node to point to previous node.

  • Free the node

CODE :

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *del;
    int n, i, value, pos;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;
        newNode->prev = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            newNode->prev = temp;
            temp = newNode;
        }
    }

    printf("\nBefore deletion:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL\n");

    printf("\nEnter position to delete: ");
    scanf("%d", &pos);

    temp = head;
    for (i = 1; i < pos; i++)
        temp = temp->next;

    if (temp->prev != NULL)
        temp->prev->next = temp->next;
    if (temp->next != NULL)
        temp->next->prev = temp->prev;

    free(temp);

    printf("\nAfter deleting middle node:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :



 7.Searching an Element from the Linked List :-
  • Traverse from head to tail.

  • Compare each node’s data with the key.

  • Print position if found.

CODE : 

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL;
    int n, i, value, key, pos = 1, found = 0;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;
        newNode->prev = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            newNode->prev = temp;
            temp = newNode;
        }
    }

    printf("Enter element to search: ");
    scanf("%d", &key);

    temp = head;
    while (temp != NULL) {
        if (temp->data == key) {
            found = 1;
            break;
        }
        pos++;
        temp = temp->next;
    }

    if (found)
        printf("Element found at position %d", pos);
    else
        printf("Element not found");

    return 0;
}

Output  :




 8. Sorting a Linked List :-
  • Use bubble sort or other simple algorithms.

  • Compare data of nodes and swap values if needed.

  • Traverses using two nested loops.

CODE :

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *prev;
    struct Node *next;
};

int main() {
    struct Node *head = NULL, *temp = NULL, *i, *j;
    int n, value, swap;

    printf("Enter number of nodes: ");
    scanf("%d", &n);

    for (int k = 0; k < n; k++) {
        struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &value);
        newNode->data = value;
        newNode->next = NULL;
        newNode->prev = NULL;

        if (head == NULL) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            newNode->prev = temp;
            temp = newNode;
        }
    }

    for (i = head; i != NULL; i = i->next) {
        for (j = i->next; j != NULL; j = j->next) {
            if (i->data > j->data) {
                swap = i->data;
                i->data = j->data;
                j->data = swap;
            }
        }
    }

    printf("Sorted Doubly Linked List:\n");
    temp = head;
    while (temp != NULL) {
        printf("%d <-> ", temp->data);
        temp = temp->next;
    }
    printf("NULL");

    return 0;
}

Output  :


3.Circular Linked List :-
  • A circular linked list is that in which the last node contains the pointer to the first node of the list. 
  • While traversing a circular linked list, we can begin at any node and traverse the list in any direction forward and backward until we reach the same node we started. Thus, a circular linked list has no beginning and no end. Below is the image for the same:
Diagram of Circular Linked List :-


Types  of a Circular linked list:-

1. Singly Circular Linked List :-
  •  A circular linked list is a variation of a singly linked list. The only difference between the singly linked list and a circular linked list is that the last node does not point to any node in a singly linked list, so its link part contains a NULL value. 
  • The circular linked list is a list in which the last node connects to the first node, so the link part of the last node holds the first node's address.
  • The circular linked list has no starting and ending node. We can traverse in any direction, i.e., either backward or forward.   
  • We can traverse in any direction, i.e., either backward or forward. 
  • The diagrammatic representation of the circular linked list is shown below:
Representation of the node in a Circular linked list:-

struct node { 
 int data; 
 struct node *next; 
 }   


Memory Representation of a Circular linked list :-

2. Doubly Circular Linked List :-
  •  The doubly circular linked list has the features of both the circular linked list and doubly linked list. 
  • The diagrammatic representation of the Doubly circular linked list is shown below:

Representation of the node in a Doubly Circular linked list:-

struct node { 
int data; 
struct node *next; 
struct node *prev;
 }   

Memory Representation of a Doubly Circular linked list :-