HomePythonPython Program to Implement Circular Doubly Linked List

# Python Program to Implement Circular Doubly Linked List

A circular doubly linked list is an advanced version of a linked list where each node contains pointers to both the next and previous nodes. This Python program demonstrates the implementation and various operations on a circular doubly linked list using Python.

## Problem Statement

Given the concept of a circular doubly linked list, your task is to implement the necessary operations to create, append elements, and display the circular doubly linked list.

## Python Program to Implement Circular Doubly Linked List

```class Node:
def __init__(self, data):
self.data = data
self.next = None
self.prev = None

def __init__(self):

def append(self, data):
new_node = Node(data)
else:
current.next = new_node
new_node.prev = current

def display(self):
print("List is empty")
return
while True:
print(current.data, end=" <-> ")
current = current.next
break
print("...")

# Input: Creating a circular doubly linked list
elements = [1, 2, 3, 4, 5]
for element in elements:
circular_list.append(element)

circular_list.display()
```

## Input / Output

### You May Also Like

#### Python Program to Remove Duplicates from a Linked List

In this Python program, we will create a singly linked list and remove duplicate elements from it. A linked list...

#### Python Program to Solve the Celebrity Problem

This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...

#### Python Program to Solve n-Queen Problem with Recursion

This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...