Circular Linked List Introduction

Circular linked list is variation of singly linked least where instead of keeping NULL in last node we keep the address of some other node. This makes link list circular . In the below diagram we have kept the address of start to last node of list instead of keeping NULL. This makes list circular.



Here we have utilized list last node , but lets see some analysis on this.

1) To insert the node in last , we will have to traverse the linked list and then add the new node to next of last node and assign the new node to start again. Thus the insert at last is similar to singly linked list.

2) To insert a new node in first, for singly linked list we need not require traverse. But in circular list when we add new node to first then the next of first node should have address of last node in list to make circular , again we will have to traverse till the last node to get address of last element.

3) To delete the node at start , for linked list we don't have to traverse the list , we can assign the address in next pointer to start and need not to traverse the list. But in circular linked list if we delete the first node the second node becomes the first node and we will have to store the address of last node to first. Again traversing is required.

4) Similarly to delete at any position even at last we will have to traverse since after deleting we need to assign address of previous element to the start.

So idea of keeping the address of first node in next of last node isn't a good option as traversing is required in any case.

Lets change this idea and make the start node as last.  The next node of last will be the first node in list. 

If we add the new node to last below would be the sequence.  



Now if we want to add the new node to the start , below would be the sequence.








 


Comments