Circular doubly linked list is a mixture or combination of doubly linked list and circular linked list. In a circular doubly linked list two successive nodes are linked by previous pointer and next pointer. The first node points to the last node by the previous pointer and the last node points to the first node by the next pointer.
Example– The below example shows us how to create circular doubly linked list and how to traverse it.
Advantages of Circular Doubly Linked List:
-
We can traverse the list from both sides i.e. from first node to the last node or last node to the first node. We can jump from first node to last node or last node to first node in O(1) i.e. in constant time complexity.
-
We can implement some complex data structure like a fibonacci heap using a circular doubly linked list.
Disadvantages of Circular Doubly Linked List:
-
You can see in the above example, we have to maintain a lot of pointers to implement a circular doubly linked list. So, we have to handle pointers carefully otherwise the data of the linked list may be lost.
-
Because of a lot of pointers it takes extra memory.
Applications of Circular Doubly Linked List:
-
In a media player, a circular doubly linked list is used in order to maintain songs in the playlist.
-
Also this data structure is used in e-commerce websites to maintain shopping carts.
Also read: Circular Linked List
Be First to Comment