Professional Documents
Culture Documents
Unit IV - Doubly and Circular Link List
Unit IV - Doubly and Circular Link List
Unit -IV
• Doubly Link List(DLL)
• Circular Link List
pervious next
10
struct Node {
int data;
struct Node * next; // Pointer to next node in DLL
struct Node * prev; // Pointer to previous node in DLL
};
Doubly Link List
next next
next
Doubly Circular Link List
• In doubly linked list, the next pointer of the
last node points to the first node and the
previous pointer of the first node points to the
last node. previous
previous previous
next
Operations on Circular Link List
• Creation of node
• Creation of Link List
• Insertion
– Insert a node at beginning
– Insert node at End
– Insert node inbetween
• Deletion
– Delete First node
– Delete Last node
– Delete node inbetween
• Searching
• Traversing
Algorithm for Operations on Singly Circular
Link List
Algorithm for Creation of Node
• Step 1 - Allocate memory for newnode using malloc function
• Step 2 - Read the value for newnode in ‘val’ variable.
• Step 3- set newnode->data=val
newnode->next=start
start next
10
Algorithm for Insertion of newnode at beginning
• Step 1 - Create a newNode with given value.
• Step 2 - Check whether list
is Empty (start == NULL)
• Step 3 - If it is Empty then, set start= newNode.
newNode→next = start
• Step 4 - Initialize another pointer ‘p’ to address of
start. Traverse this pointer till it gets address of
start pointer.
• set - start = newNode.
p->next=newNode
Insert NewNode 50 at Beginning
NewNode
P
50
next
start
10 20 30
Algorithm for Insertion of newnode at the End
start next
10 20 30
Algorithm of Delete from Beginning
• Step 1 - Check whether list is Empty (start == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!!
Deletion is not possible' and terminate the function.
• Step 3 - If it is Not Empty then, define a Node
pointer ‘p' and initialize with start. Traverse this
pointer till it gets address of start pointer.
• Step 4- set p → next=start->next, and delete start.
set start->p->next
Delete Node 10
start next
10 20 30
p->next=start->next
delete (start)
start=p->next
Algorithm for Delete from End
• Step 1 - Check whether list is Empty (start == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion
is not possible' and terminate the function.
• Step 3 - If it is Not Empty then, define a Node
pointer ‘p' and initialize with start. Traverse this pointer till
it gets address of start pointer.
• Step 4-set temp = p and move p to its next node. Repeat
the same until it reaches to the last node in the list. (until p
→ next == start)
• Step 5- set temp → next=p->next, and delete p.
Delete Node 30
P temp
next
start
10 20 30
temp->next=p->next
delete(p)
Thank You