Double Linked List
Double Linked List
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
. …… 65
NULL …..
6565 …..
…
1000
1000 5000
Null 10 2000 1000 56 3000 2000 48 Null
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
21