Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

K. K.

Wagh Polytechnic, Nashik


Department of Computer Technology

Course: Data Structure Using ‘C’


DSU-22317

Unit -IV
• Doubly Link List(DLL)
• Circular Link List

Prepared and Presented By:


Mrs. M. A. Shaikh
Doubly Link List
• A Doubly Linked List (DLL) contains an extra
pointer called previous pointer to point to
previous node in the link list.
• In Doubly Linked List is a variation of singly link
list in which navigation is possible in both
ways, either forward and backward.
• It contains two pointer:
– Next-to point to address of next node
– Previous-to point to address of previous node
Node in DLL

pervious next
10

Structure of Node in DLL

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

start next next next


10 20 30
previous previous previous
Operations in DLL
• 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
Advantages of DLL over SLL
• A DLL can be traversed in both forward and
backward direction.
• The delete operation in DLL is more efficient if
pointer to the node to be deleted is given.
• We can quickly insert a new node before a given
node.
• In singly linked list, to delete a node, pointer to the
previous node is needed. To get this previous node,
sometimes the list is traversed. In DLL, we can get
the previous node using previous pointer.
Disadvantages of DLL over SLL
• Every node of DLL Require extra space for an
previous pointer.
• All operations require an extra pointer
previous to be maintained.
• For example, in insertion, we need to modify
previous pointers together with next pointers.
Circular Link List
• Circular Linked List is a variation of Linked list
in which the first node points to the last node
and the last node points to the first node.
• Both Singly Linked List and Doubly Linked List
can be made into a circular linked list.
– Singly Circular Link List
– Doubly Circular Link List
Singly Circular Link List
• In singly circular linked list, the next pointer of
the last node points to the first node.

next next

start Node 1 Node 2 Node 3 next


10 20 30

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

start next next


10 10 10 next

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

• 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 - p->next=NewNode
Newnode->next=start
Insert NewNode 50 at the End
NewNode
P
50

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

You might also like