Circular Doubly Linked List

A Circular Doubly Linked List combines features of both circular and doubly linked lists. Each node has pointers to both the next and previous nodes, and the last node's next pointer points to the first node, while the first node's previous pointer points to the last node.

Key characteristics:

  1. Bidirectional circular structure: Can be traversed in both directions without endpoints.
  2. Each node has three components: data, next pointer, and previous pointer.
  3. The first node's previous points to the last node, and the last node's next points to the first node.
  4. Allows for efficient insertion and deletion at both ends of the list.

Key operations:

  1. Insertion (at the beginning, end, and at a specific position)
  2. Deletion (from any position)
  3. Forward and backward traversal
  4. Searching for an element

Real-world applications:

  1. Implementation of advanced data structures like Fibonacci Heap
  2. Managing multiple applications in a multi-tasking operating system
  3. Implementing browser cache with efficient forward and backward navigation
  4. Undo-redo functionality in applications
  5. Designing music players with repeat-all functionality and bi-directional song navigation
Node Structure

Circular Doubly Linked List(CDLL) Operations: Pseudocode For Insertions

First we write the Pseudocode for Circular Doubly Linked List Operations

  • Add a node at the beginning. 
  • Adding a node at the end.
  • Adding a node at a specific position.
Adding a node at a specific position.

Add Node at First

Add Node at Last

Code for Insertions In Circular Doubly Linked List (CDLL)

Code for Insertions In Circular Doubly Linked List (CDLL):

  • Add a node at the beginning. 
  • Adding a node at the end.
  • Adding a node at a specific position.
  • Print Circular Doubly Linked List Forward
  • Print Circular Doubly Linked List Reverse
Full Code

Code Output
Forward Direction
20->10->5->15->null
Reverse Direction
15->5->10->20->null