0% found this document useful (0 votes)
25 views

Double Linked List

linked list

Uploaded by

pratikkedia2806
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Double Linked List

linked list

Uploaded by

pratikkedia2806
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Lecture

Double Linked List


01 Data Structure

Different Operations
02 On Double Linked List
2

Double
Linked List
3
Node Structure & Chain Formation
Node Representation typedef s t r u c t node
in singly Linked List{
i n t dat a;
Node Representation s t r u c t node * n e x t ;
in singly Circular
Node Structure

}node;
Linked List

typedef s t r u c t node
Node Representation {
in doubly Linked List i n t dat a;
s t r u c t node * n e x t ;
s t r u c t node * p r e v ;
}node;
4
Operations Performed on Double Linked List
We can perform following basic operations on Double Linked List.
1. Creating Linked List
2. Traversing Linked List
3. Printing Linked List
Operations

4. Counting Number of Nodes in Linked List


5. Searching Element in Linked List
6. Concatenating two Linked List
7. Inserting element into Linked List (Start, End and Specific Position)
8. Deleting elements from Linked List (Start, End and Specific Position)
9. And Many more operations.
Creation Operation on DLL
6
Create Operations on Double Linked List
Head Tail

Null 10 2000 1000 56 3000 2000


2000 48 Null
5000 .3000
…… 65
3000 …..
65
65 NULL
…..

1000 2000 3000 5000


Algorithm CreateByInsertAtLast(Head, Tail):
1. Accept ITEM
2. node * Temp = (node*)malloc(sizeof(node))
3. Temp->data= ITEM
Create Operation #01

4. IF HEAD == NULL Then


Head=Tail=Temp
Tail -> next = NULL
Head- >prev= NULL
5. Else
Tail -> next=Temp
Temp->next= NULL
Temp-> prev=Tail
Tail=Temp
6. End If
7. If you insert more then GOTO step 1
8. Stop
7
8
Create Operations on Double Linked List
Head Tail

. …… 65
NULL …..
6565 …..

1000
1000 5000
Null 10 2000 1000 56 3000 2000 48 Null

1000 2000 3000


5000 Algorithm CreateByInsertAtFirst(Head, Tail):
1. Accept ITEM
2. node * Temp = (node*)malloc(sizeof(node))
3. Temp->data= ITEM
4. IF HEAD == NULL Then
Head=Tail=Temp
Create Operation # 02

Tail -> next = NULL


Head- >prev= NULL
5. Else
Temp->next= Head
Head->prev=Temp
Temp- >prev= Null
Head=Temp
6. End If
7. If you insert more then GOTO step 1
Traversing Operation on
DLL
10
Traversing Operations on Double Linked List

Algorithm TraversingForward(Head):
1. ptrH= Head
2. while( ptrH != NULL)
Print ptrH->data
ptr =ptrH ->next
3. End While

Algorithm TraversingBackward(Tail):
1. ptrT= Tail
2. while( ptrT != NULL)
Print ptrT->data
ptrT =ptrT ->prev

Traversing
3. End While
Insert After Operation on
DLL
Insert After operation 12
5000 5000
on Double Linked List

Insert After
5. IF flag==0 Then
…..
…..
….. …..
2000 65
65 ……
3000
……
3000
Print “Item Not Found”
5000 return
6.End If
7. node * Temp = (node*)malloc(sizeof(node))
Algorithm InsertAfter(Head,Tail,ITEM,Element): 8. Temp->data= Element
1. ptr= Head 9. Temp->next= ptr->next
2. flag=0 10. If ptr- >next !=Null Then
3. while( ptr != NULL) ptr->next->prev= Temp
IF ptr->data == ITEM Else
flag=1 Tail=temp
break 11. ptr->next =Temp
End If 12. Temp->prev= ptr
ptr =ptr ->next 13. Stop
4. End While
Delete a Node Operation on
DLL
14
15
16
17
18
19
20
Assignments on Double Link List
1. Create a Double Link List which will store the information about
students(name, roll,address, marks) and perform the following
operations on it
i) Sort the List based on Roll no
ii) Alter the information of a student whose name is Y.
iii) List all the student information whose marks are in
between 80 to 100.
References

1. “Data Structures And Program Design In C”, 2/E by


Robert L. Kruse, Bruce P. Leung.
2. “Fundamentals of Data Structures of C” by Ellis
Horowitz, SartajSahni, SusanAnderson-freed.
3. “Data Structures in C” by Aaron M. Tenenbaum.
4. “Data Structures” by S. Lipschutz.
5. “Data Structures Using C” by ReemaThareja.
6. “Data Structure Using C”, 2/e by A.K. Rath, A. K. Jagadev.
7. “Introduction to Algorithms” by Thomas H. Cormen,
Charles E. Leiserson, Ronald L. Rivest, Clifford Stein

21

You might also like