Posted in  Vinay Khatri
Last updated on July 28, 2022

A circular doubly list is a combination of doubly and circular lists; it inherits the properties of both the data structures. Consequently, this makes circular doubly quite complex. Similar to a circular linked list, performing traversing in the circular doubly linked list could lead to an infinite loop. Thus, you need to be extra careful while writing the traversal operation for this data structure.

As it contains the properties of doubly linked list DS, the Circular Doubly linked list has two pointers, namely pre and next, that point to the previous and next node respectively. Unlike a simple doubly linked list, the last node next pointer of the Circular linked list points to the head of the circular doubly linked list DS.

If we compare circular doubly linked lists to other linked list data structures, it emerges as the most expensive data structure for space and basic operations. However, it provides an easy approach for pointer manipulation, and searching becomes two times more efficient.

• We can traverse back and forth using the next and pre-pointers.
• As the last element is linked with the head, we can easily jump from the tail to the head of the data structure.
• It is an ideal choice for implementing complex data structures.

• As the circular doubly list needs two pointers for each node, it occupies extra space.
• The pointers must point to the right data or object and no do not point to the Null value. In case the pointers point towards the Null value, it will result in the loss of the data.

## Supported Operations

We can perform various operations on the Circular doubly list. Like other data structures , there are some standard and basic operations that we can perform on this data structure, which are listed as follows:

• Insertion at the beginning
• Insertion at the end
• Traversal
• Deletion at the beginning
• Deletion at the end.

## Implementation of Circular Doubly Linked List in Python:

Here's a sample code that highlights the implementation of a circular doubly list in Python:

``````using namespace std;
struct Node {
int data;
struct Node* next;
struct Node* pre;
};
void insert(struct Node** Head, int data)
{
struct Node* new_node = new Node;
new_node->data = data;
new_node->next = new_node->pre = new_node;
return;
}
struct Node* new_node = new Node;
new_node->data = data;
new_node->pre = last;
last->next = new_node;
}
void remove(struct Node** Head, int key)
{
return;
struct Node *curr = *Head, *pre_1 = NULL;
while (curr->data != key) {
printf("\nList doesn't have node with data = %d", key);
return;
}
pre_1 = curr;
curr = curr->next;
}
if (curr->next == *Head && pre_1 == NULL) {
free(curr);
return;
}
free(curr);
}

else if (curr->next == *Head) {
free(curr);
}
else {
struct Node* temp = curr->next;
pre_1->next = temp;
temp->pre = pre_1;
free(curr);
}
}
{
{
printf("%d ", temp->data);
temp = temp->next;
}
printf("%d ", temp->data);
}
int main()
{
return 0;
}``````

## Conclusion

We hope that this post helped you develop a basic understanding of the Doubly Circular Linked List. To make sure you remember, we would like to repeat that it is a data structure that has properties of both the doubly and circular linked lists.