Doubly and Circular Linked List

A circular doubly linked list is a doubly linked list with the first node linked to the last node and vice-versa. A circular doubly linked list is shown in the following figure.

In case of the circular list with header node, the ‘prev’ link of the node and the ‘next’ link of the last node points to the header node. And, the ‘prev’ and ‘next’ link of the header node points to the last node and first node respectively.

In case of the circular list without header node, the ‘next’ link of the last node point to the first node and ‘prev’ link of the first node points to the last node.

The main advantage of a circular doubly linked list is that a node can be inserted into a list without searching the complete list for finding the address of the previous node.

Doubly and Circular Linked List Advantage

Doubly and Circular Linked List Disadvantages

Operations on Circular Doubly Linked List

The basic operations that can be performed on a circular doubly linked list are,

Circular Doubly Linked List Traversal

A circular doubly linked list can be traversed in both directions i.e., from the first node to the last node and vice-versa (with the help of ‘next’ and ‘prev’ points respectively).

Algorithm: CDL-traverse (head)

Circular Doubly Linked List Insertion

The insertion of a node into the circular doubly linked list can be at different locations, i.e., at the beginning of the list, at a specified location in the list, at the end of the list.

Algorithm: CDL-insert (head,ptr)

Circular Doubly Linked List Deletion

A node can be deleted from the circular doubly linked list at any position in the list

Algorithm: CDL-delete (head,pos)