Circular Linked List
Circular Linked List
That means circular singly linked list is similar to the single linked list
except that the last node points to the first node in the list
Example
Operations:
We can use the following steps to insert a new node at end of the circular linked
list...
Step 1 - Create a newNode with given value.
www.vectorindia.org 1
Circular Linked List
We can use the following steps to delete a specific node from the circular linked
list...
Step 1 - Check whether list is Empty (head == NULL)
Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not
possible' and terminate the function.
Step 3 - If it is Not Empty then, define two Node pointers 'temp1' and
'temp2' and initialize 'temp1' with head.
Step 4 - Keep moving the temp1 until it reaches to the exact node to be
deleted or to the last node. And every time set 'temp2 = temp1' before
moving the 'temp1' to its next node.
Step 5 - If it is reached to the last node then display 'Given node not found
in the list! Deletion not possible!!!'. And terminate the function.
www.vectorindia.org 2
Circular Linked List
Step 6 - If it is reached to the exact node which we want to delete, then check
whether list is having only one node (temp1 → next == head)
Step 7 - If list has only one node and that is the node to be deleted then set
head = NULL and delete temp1 (free(temp1)).
Step 8 - If list contains multiple nodes then check whether temp1 is the first
node in the list (temp1 == head).
Step 9 - If temp1 is the first node then set temp2 = head and keep moving
temp2 to its next node until temp2 reaches to the last node. Then set head
= head → next, temp2 → next = head and delete temp1.
Step 10 - If temp1 is not first node then check whether it is last node in the
list (temp1 → next == head).
Step 1 1- If temp1 is not first node then set temp2 → next = temp1 → next
and delete temp1 (free(temp1)).
Example:
www.vectorindia.org 3
Circular Linked List
www.vectorindia.org 4
Circular Linked List
Note :
www.vectorindia.org 5