Wednesday, 26 July 2017

Circular Doubly Linked List- data Structures


A circular doubly linked list is a simple doubly linked list in which prev link of the first node points to the last node and the next link of the last node points back to the start node .

First node have the address of last node and last node have the address of first node.

Real life example is train in which guard have the information of driver and Vice Versa.

circular DLL image

Creating a circular doubly linked list with 'N' number of Nodes

Step 1: Create the NEW_NODE using createnode()

NEW_NODE = createnode();

Step 2: If the linked list is empthy (START == NULL)

START = NEW_NODE
NEW_NODE-> NEXT = START
NEW_NODE ->PREV = START

Step 3: If the linked list is not empthy

NEW_NODE ->NEXT = START
NEW_NODE ->PREV = START ->PREV
START -> PREV -> NEXT = NEW_NODE
START -> PREV = NEW_NODE

Step 4 : Repeat Steps 1,2,3 'N' times

Step 5 : EXIT

Inserting a Node at the Beginning of a Circular Doubly Linked List

Step 1: Create the NEW_NODE using createnode()

NEW_NODE = createnode();

Step 2: If the linked list is empthy (START == NULL)

START = NEW_NODE
NEW_NODE-> NEXT = START
NEW_NODE ->PREV = START

Step 3: If the linked list is not empthy

NEW_NODE ->PREV = START -> PREV
NEW_NODE -> NEXT = START
START -> PREV -> NEXT = NEW_NODE
START -> PREV = NEW_NODE
START = NEW_NODE

Step 4 : EXIT

Inserting a NEW Node at the End of a Circular Doubly Linked List

Step 1: Create the NEW_NODE using createnode()

NEW_NODE = createnode();

Step 2: If the linked list is empthy (START == NULL)

START = NEW_NODE
NEW_NODE-> NEXT = START
NEW_NODE ->PREV = START

Step 3: If the linked list is not empthy

NEW_NODE -> PREV = START ->PREV
NEW_NODE -> NEXT = START
START -> PREV -> NEXT = NEW_NODE
START -> PREV = NEW_NODE

Step 4 : EXIT

Share this

0 Comment to "Circular Doubly Linked List- data Structures "

Post a Comment