Circularly linked list is a linked list where all nodes are connected to form a circle.There is no end or rear or null pointer.
Circularly Linked List |
Circular linked list can be implemented in both singly linked list as well as doubly linked list.
The only difference between implementation of a circularly linked list and other linked list is that, Circularly linked list doesn't have a last element instead points to the head.Whereas other linked list points to null in place of the head.
The only difference between implementation of a circularly linked list and other linked list is that, Circularly linked list doesn't have a last element instead points to the head.Whereas other linked list points to null in place of the head.
To traverse through all the elements in the circularly linked list, we need to use two loops
- One which checks the condition that the head reference is not equal to null
- Other loop which checks if the loop doesn't repeat. i.e temp variable doesn't equal to head.
Function to push an element into the Circularly linked list
Source: Geeksforgeeks
Also Refer to Tortoise-Hare Algorithm