What is Circular Linked list ? - data structure tutorial


Prerequisites are that you must have basic knowledge of linked lists. If no, then press on the links below to learn about linked lists before reading this post on What is Circular Linked list ? - data structure tutorial.
A circular linked list is a linked list in which the last node points to the first node. A circular linked list can be a singly circular linked list or a doubly circular linked list.


We will be studying the singly circular linked list because the doubly circular linked list is not much used because it is expensive.


What is Circular Linked list ? - data structure tutorial




Advantages of Circular Linked Lists
  •  We can traverse through any node and we can stop whenever the visited node is visited again.  
  •  We don't require two pointers for front and rear. We just need to maintain a pointer to the last inserted node and the front can always be obtained as next of the last node (What is Circular Linked list in Data Structures?). 
  •   Circular lists are useful in applications to repeatedly go around the list. For example, when multiple applications are running on a PC, it is common for the operating system to put the running applications on a list and then to cycle through them, giving each of them a slice of time to execute, and then making them wait while the CPU is given to another application. It is convenient for the operating system to use a circular list so that when it reaches the end of the list it can cycle around to the front of the list. 
Disadvantages of Circular linked list
  •  The circular list is complex as compared to singly-linked lists. 
  •   Reversing of the circular list is complex as compared to singly or doubly lists. 
  •  Must be traversed carefully, else we could end up in an infinite loop.
  •  Like singly and doubly lists circular linked lists also don’t support direct accessing of elements.

Basic Operations

The following are the important operations of a circular list.
·      insert – To insert elements in the linked list.
·      delete – To delete elements from a linked list.
·     display – To displays the list (What is Circular Linked list in Data Structures?).


Insertion:

1.      Insertion at Beginning:  To insert a node at the beginning of the linked list.

What is Circular Linked list ? - data structure tutorial






 
2.     Insertion at End:  To insert a node at the end of the linked list.

What is Circular Linked list ? - data structure tutorial








Deletion:


1.      Deletion at Beginning:  To delete a node at the beginning of the linked list.


What is Circular Linked list ? - data structure tutorial









2.      Deletion at End:  To delete a node at the end of the linked list.


What is Circular Linked list ? - data structure tutorial








Try practicing some programs based on circular linked list:



·       WAP to count number of nodes in a circular linked list.




Comment below if you want solution of any of the above programs (What is Circular Linked list ? - data structure tutorial).

Post a Comment (0)
Previous Post Next Post