Circular Linked List
- Circular Linked List is another type of Linked list.
- Circular Linked List is a variation of the Linked list in which the first element points to the last element and the last element points to the first element.
- We can create the following types:
- Singly Circular Linked List: In a singly linked list, the next pointer of the last node points to the first node.
- Doubly Circular Linked List: In a doubly-linked list, the next pointer of the last node points to the first node and the previous pointer of the first node points to the last node making the circular in both directions.
- The following are the basic operations supported by a list.
- Insertion −
- Insert Begin - Adds an element at the beginning of the list.
- Insert Last − Adds an element at the end of the list.
- Insert desired position - Add an element as per given position.
- Deletion −
- Delete Begin - Deletes an element at the beginning of the list.
- Delete Last − Deletes an element from the end of the list.
- Delete (Key)− Deletes an element from the list using the key.
- Delete (Position) - Deletes an elements as per given position.
- Display
- Forward − Displays the complete list in a forward manner.
- Backward − Displays the complete list in a backward manner.
- 1) Any node can be a starting point. We can traverse the whole list by starting from any point. We just need to stop when the first visited node is visited again.
- 2) Useful for implementation of a queue.
- 3) Circular lists are useful in applications to repeatedly go around the list. For example, when multiple applications are running on a PC, 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.
- 4) Circular Doubly Linked Lists are used for the implementation of advanced data structures like Fibonacci.
Tags:
data structure