Upcoming SlideShare
×

2,418 views
2,356 views

Published on

1 Comment
6 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No

Are you sure you want to  Yes  No
Views
Total views
2,418
On SlideShare
0
From Embeds
0
Number of Embeds
428
Actions
Shares
0
0
1
Likes
6
Embeds 0
No embeds

No notes for slide

1. 1. Presentation on doubly linked list:- Presented by:- RITU NAMDEO M.C.A. 2 ND SEM ‘ B’ SEC. MITM INDORE
2. 2. Doubly linked list <ul><li>Doubly-linked list(DLL) is a more sophisticated kind of linked list. </li></ul><ul><li>Each has three parts ,two links parts and one data parts. </li></ul><ul><li>One points to previous node and one points to next node. </li></ul><ul><li>There are two pointer variable head and tail. </li></ul><ul><li>Head points to the first element of list and tail points last element of list. </li></ul>
3. 3. REPRESENTATION OF DLL <ul><li>PPPP </li></ul>D D P D N D Head Tail
4. 4. DLL OPERATIONS: <ul><li>INITIALIZING </li></ul><ul><li>CREATING A NODE </li></ul>
6. 6. Code <ul><li>initialization >>.. </li></ul><ul><li>initialize(node **head,node **tail){ </li></ul><ul><li> *head=NULL; </li></ul><ul><li> *tail=NULL; </li></ul><ul><li> } </li></ul>
7. 7. Creating a node data ptr tail
8. 8. Function for creating a node <ul><li>node* create(int item){ </li></ul><ul><li> node *ptr; </li></ul><ul><li> ptr=(node*)malloc(sizeof(node)); </li></ul><ul><li> ptr->item=item; </li></ul><ul><li> ptr->prev=NULL; </li></ul><ul><li> ptr->next=NULL; </li></ul><ul><li> return ptr; </li></ul>
9. 9. OPERATIONS ON DLL <ul><li>INSERTION </li></ul><ul><li>At beginning of list </li></ul><ul><li>At end of list </li></ul><ul><li>After a specified node </li></ul><ul><li>Before a specified node </li></ul><ul><li>Deletion </li></ul><ul><li>At beginning of list </li></ul><ul><li>At end of list </li></ul><ul><li>After a specified node </li></ul><ul><li>Before a specified node </li></ul><ul><li>Traversing </li></ul>
10. 10. Insertion at begining <ul><li>Check for list is empty or not. </li></ul><ul><li>insrt_beg(node **head,node **tail,itemtype item) </li></ul><ul><li>{ </li></ul><ul><li>node *ptr; </li></ul><ul><li>ptr=create(item); </li></ul><ul><li>if(*head==NULL&&*tail==NULL){ </li></ul><ul><li>*head=ptr; </li></ul><ul><li>*tail=ptr; </li></ul><ul><li>} </li></ul>Head Tail
11. 11. Insertion at beginning <ul><li>Before insertion </li></ul>20 10 30 Head Tail
12. 12. <ul><li>new node </li></ul>2 ptr tail
13. 13. <ul><li>Insertion </li></ul>2 ptr tail 20 10 30 Head Tail
14. 14. <ul><li>Insertion of new node </li></ul>10 2 20 Head Tail 30
16. 16. Insert at last of list <ul><li>new node before insertion </li></ul>40 ptr tail
17. 17. 40 ptr tail 20 10 30 Head Tail
18. 18. <ul><li>After insertion new node </li></ul>20 10 30 Head Tail 40
19. 19. Code for this operation:- <ul><li>insrt(node ** head,node **tail,itemtype item){ </li></ul><ul><li>node *ptr; </li></ul><ul><li>ptr=create(item); </li></ul><ul><li>if(*head==NULL&& *tail==NULL){ </li></ul><ul><li>*head=ptr; </li></ul><ul><li>*tail=ptr; </li></ul><ul><li>} </li></ul><ul><li>else{ </li></ul><ul><li> ptr->prev=*tail; </li></ul><ul><li> (*tail)->next=ptr; </li></ul><ul><li> *tail=ptr; </li></ul><ul><li> ptr=NULL; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul>
20. 20. Insertion before a specified node:- <ul><li>new node </li></ul>40 ptr tail
21. 21. Inserting new node <ul><li>Inserting before 30 </li></ul>20 10 40 Head Tail 30
23. 24. Cont. <ul><li>} </li></ul><ul><li> if(temp==NULL) </li></ul><ul><li> printf(&quot;item was not found&quot;); </li></ul><ul><li> else { </li></ul><ul><li> temp1=temp->prev; </li></ul><ul><li> ptr->prev=temp1->next; </li></ul><ul><li>temp1->next=ptr; </li></ul><ul><li> ptr->next=temp; </li></ul><ul><li> temp->prev=ptr; </li></ul><ul><li> ptr=NULL; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul>
24. 25. After a specified node <ul><li>New node </li></ul>40 ptr tail
25. 26. <ul><li>Inserting after 20: </li></ul>20 10 40 Head Tail 30
27. 28. Cont. <ul><li>} </li></ul><ul><li> if(temp==NULL) </li></ul><ul><li> printf(&quot;item was not found&quot;); </li></ul><ul><li> else { </li></ul><ul><li> temp1=temp->next; </li></ul><ul><li> ptr->prev=temp; </li></ul><ul><li> ptr->next=temp->next; </li></ul><ul><li> temp1->prev=ptr; </li></ul><ul><li> temp->next=ptr; </li></ul><ul><li> ptr=NULL; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
28. 29. Deletion in DLL <ul><li>Deletion at begining </li></ul><ul><li>case :-if list is empty. </li></ul>Head Tail