Circular Linked List
Circular Linked List
■ Traverse
■ Search
■ Insert
■ Delete
INTRODUCTION
▪ A header linked list is a special type of linked list which contains
a header node at the beginning of the list. So, in a header linked
list START will not point to the first node of the list but START
will contain the address of the header node. There are basically
two variants of a header linked list-
▪ Grounded header linked list which stores NULL in the next field
of the last node
▪ Circular header linked list which stores the address of the
header node in the next field of the last node. Here, the
header node will denote the end of the list.
Header Node
1 2 3 4 5 6 X
START
Header Node
1 2 3 4 5 6
START
INTRODUCTION
• In a circular linked list, the last node contains a pointer to the first
node of the list. We can have a circular singly listed list as well as
circular doubly linked list. While traversing a circular linked list,
we can begin at any node and traverse the list in any direction
forward or backward until we reach the same node where we
had started. Thus, a circular linked list has no beginning and no
ending.
START
1 2 3 4 5 6 7
– Circular linked list are of two types:
A B C
1 7 3 4 2 6 5
START, PTR
1 7 3 4 2 6 5
START
9 1 7 3 4 2 6 5
START
Algorithm to insert a new node in the beginning of
circular the linked list
START, PTR
1 7 3 4 2 6 5 9
PTR
START
1 7 3 4 2 6 5
PTR
START
7 3 4 2 6 5
Algorithm to delete the first node from the circular linked list
1 7 3 4 2 6 5
PREPTR
PTR
START
1 7 3 4 2 6
START
1 7 3 4 2 6 5
1 7 3 4 6 5
START
Algorithm to delete the node after a given node from the circular linked list
START
9 1 7 3 4 2
START
1 7 3 4 2 9
START
X 1 3 5 7 8
START