Data Structure Module-3 Doubly Linked List
Data Structure Module-3 Doubly Linked List
Algorithms
Module -3
Doubly Linked List
Dr. R. Jothi, SCOPE
VIT Chennai
Outline
Types of Linked List
Circular Linked List
Doubly Linked List
Head A B C
Circular Singly Linked List
Each node in the list has only one pointer to its
successor
Last node points to first node (head) in the list
Head
A B C
Doubly Linked List
Links exist between adjacent nodes in both directions.
The list can be traversed either forward or backward.
Usually two pointers are maintained to keep track of
the list, head and tail.
head tail
A B C
Dr. R. Jothi, VIT Chennai
A node in the Doubly Linked List
struct nd {
struct item data;
struct nd *next;
struct nd* prev;
} node;
Creating Doubly Linked List
Empty DLL
Add nodes,
first node becomes head
1 3
return NULL;
} Dr. R. Jothi, VIT Chennai
Deleting a node from Doubly Linked List (1)
1. Delete a head node
Cur=Head
Head = Cur -> right;
Cur ->right -> left = NULL;
free(Cur);
Dr. R. Jothi, VIT Chennai
Deleting a node from Doubly Linked List (2)
2. Delete any other node
Disadvantages:
Requires more space
List manipulations are slower (because
more links must be changed)