SlideShare a Scribd company logo
1 of 8
Programming and Data Structures
Lecture #1
Doubly Linked List
A Doubly Linked List (DLL) contains an extra pointer, typically called previous
pointer, together with next pointer and data which are there in singly linked
list.
2
DOUBLY LINKED LIST:
Courtesy: https://www.geeksforgeeks.org/circular-linked-list/
Advantages of Doubly Linked Lists over singly linked list
1. A DLL can be traversed in both forward and backward direction
2. Delete operation in DLL is more efficient if pointer to the node to be
deleted is given
3. 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
3
Disadvantages of Doubly Linked Lists
1. Every node of DLL requires an extra space for a previous
pointer
Though it is possible to implement DLL with single
pointer
2. All operations require an extra pointer previous to be
maintained
For example, in insertion, we need to modify previous
pointers together with next pointers
For example in functions for insertions at different positions,
we need 1 or 2 extra steps to set previous pointer
4
/* Node of a doubly linked list */
struct Node
{
int data;
struct Node* next; // Pointer to next node in DLL
struct Node* prev; // Pointer to previous node in DLL
};
5
Representation of DLL Node
We are given pointer to a node as prev_node, and the new node is
inserted after the given node.
6
Add a Node After a Given Node
/* Given a node as prev_node, insert a new node after the given node */
void insertAfter(struct Node* prev_node, int new_data)
{
/*1. check if the given prev_node is NULL */
if (prev_node == NULL) {
printf("the given previous node cannot be NULL");
return;
}
/* 2. allocate new node */
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
/* 3. put in the data */
new_node->data = new_data;
7
/* 4. Make next of new node as next of prev_node */
new_node->next = prev_node->next;
/* 5. Make the next of prev_node as new_node */
prev_node->next = new_node;
/* 6. Make prev_node as previous of new_node */
new_node->prev = prev_node;
/* 7. Change previous of new_node's next node */
if (new_node->next != NULL)
new_node->next->prev = new_node;
}
8

More Related Content

Similar to MO 2020 DS Doubly Linked List 1 AB.ppt

Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.pptMuhammadShafi89
 
DLL DATA STRUCT.pptx
DLL DATA STRUCT.pptxDLL DATA STRUCT.pptx
DLL DATA STRUCT.pptxMuwaffiqa
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
Ch-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfCh-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfesuEthopi
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1DrSudeshna
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
 
Seo Expert course in Pakistan
Seo Expert course in PakistanSeo Expert course in Pakistan
Seo Expert course in Pakistanssuserb2c86f
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocationkiran Patel
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxgilliandunce53776
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of listsmuskans14
 
Data structure week y 4
Data structure week y 4Data structure week y 4
Data structure week y 4karmuhtam
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
 

Similar to MO 2020 DS Doubly Linked List 1 AB.ppt (20)

Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Linked list
Linked listLinked list
Linked list
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.ppt
 
DLL DATA STRUCT.pptx
DLL DATA STRUCT.pptxDLL DATA STRUCT.pptx
DLL DATA STRUCT.pptx
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Ch-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfCh-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdf
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
Seo Expert course in Pakistan
Seo Expert course in PakistanSeo Expert course in Pakistan
Seo Expert course in Pakistan
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocation
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of lists
 
Data structure week y 4
Data structure week y 4Data structure week y 4
Data structure week y 4
 
Linked list
Linked list Linked list
Linked list
 
Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
 
Linked List
Linked ListLinked List
Linked List
 
Team 10
Team 10Team 10
Team 10
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 

More from shashankbhadouria4

Artificial Neural Network.pptx
Artificial Neural Network.pptxArtificial Neural Network.pptx
Artificial Neural Network.pptxshashankbhadouria4
 
IT201 Basics of Intelligent Systems-1.pptx
IT201 Basics of Intelligent Systems-1.pptxIT201 Basics of Intelligent Systems-1.pptx
IT201 Basics of Intelligent Systems-1.pptxshashankbhadouria4
 
A New Multi-Level Inverter Topology With Reduced Switch.pptx
A New Multi-Level Inverter Topology With Reduced Switch.pptxA New Multi-Level Inverter Topology With Reduced Switch.pptx
A New Multi-Level Inverter Topology With Reduced Switch.pptxshashankbhadouria4
 
Birla Institute of Technology Mesra Jaipur.pptx
Birla Institute of Technology Mesra Jaipur.pptxBirla Institute of Technology Mesra Jaipur.pptx
Birla Institute of Technology Mesra Jaipur.pptxshashankbhadouria4
 
III_Data Structure_Module_1.ppt
III_Data Structure_Module_1.pptIII_Data Structure_Module_1.ppt
III_Data Structure_Module_1.pptshashankbhadouria4
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.pptshashankbhadouria4
 
Chap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.pptChap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.pptshashankbhadouria4
 
SUmmer Training PPT FINAL.pptx
SUmmer Training PPT FINAL.pptxSUmmer Training PPT FINAL.pptx
SUmmer Training PPT FINAL.pptxshashankbhadouria4
 
MO 2020 DS Applications of Linked List 1 AB.ppt
MO 2020 DS Applications of Linked List 1 AB.pptMO 2020 DS Applications of Linked List 1 AB.ppt
MO 2020 DS Applications of Linked List 1 AB.pptshashankbhadouria4
 
III_Data Structure_Module_1.pptx
III_Data Structure_Module_1.pptxIII_Data Structure_Module_1.pptx
III_Data Structure_Module_1.pptxshashankbhadouria4
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptxshashankbhadouria4
 

More from shashankbhadouria4 (20)

EC203DSD - Module 5 - 3.ppt
EC203DSD - Module 5 - 3.pptEC203DSD - Module 5 - 3.ppt
EC203DSD - Module 5 - 3.ppt
 
Artificial Neural Network.pptx
Artificial Neural Network.pptxArtificial Neural Network.pptx
Artificial Neural Network.pptx
 
IT201 Basics of Intelligent Systems-1.pptx
IT201 Basics of Intelligent Systems-1.pptxIT201 Basics of Intelligent Systems-1.pptx
IT201 Basics of Intelligent Systems-1.pptx
 
MO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.pptMO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.ppt
 
A New Multi-Level Inverter Topology With Reduced Switch.pptx
A New Multi-Level Inverter Topology With Reduced Switch.pptxA New Multi-Level Inverter Topology With Reduced Switch.pptx
A New Multi-Level Inverter Topology With Reduced Switch.pptx
 
Birla Institute of Technology Mesra Jaipur.pptx
Birla Institute of Technology Mesra Jaipur.pptxBirla Institute of Technology Mesra Jaipur.pptx
Birla Institute of Technology Mesra Jaipur.pptx
 
EE306_EXP1.pptx
EE306_EXP1.pptxEE306_EXP1.pptx
EE306_EXP1.pptx
 
III_Data Structure_Module_1.ppt
III_Data Structure_Module_1.pptIII_Data Structure_Module_1.ppt
III_Data Structure_Module_1.ppt
 
Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
 
Chap 5 Tree.ppt
Chap 5 Tree.pptChap 5 Tree.ppt
Chap 5 Tree.ppt
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.ppt
 
Chap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.pptChap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.ppt
 
SUmmer Training PPT FINAL.pptx
SUmmer Training PPT FINAL.pptxSUmmer Training PPT FINAL.pptx
SUmmer Training PPT FINAL.pptx
 
RVPN TRAINING PPT.pptx
RVPN TRAINING PPT.pptxRVPN TRAINING PPT.pptx
RVPN TRAINING PPT.pptx
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
MO 2020 DS Applications of Linked List 1 AB.ppt
MO 2020 DS Applications of Linked List 1 AB.pptMO 2020 DS Applications of Linked List 1 AB.ppt
MO 2020 DS Applications of Linked List 1 AB.ppt
 
MO 2020 DS Stacks 1 AB.ppt
MO 2020 DS Stacks 1 AB.pptMO 2020 DS Stacks 1 AB.ppt
MO 2020 DS Stacks 1 AB.ppt
 
III_Data Structure_Module_1.pptx
III_Data Structure_Module_1.pptxIII_Data Structure_Module_1.pptx
III_Data Structure_Module_1.pptx
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
 

Recently uploaded

VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130Suhani Kapoor
 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxjanettecruzeiro1
 
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...Suhani Kapoor
 
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`dajasot375
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back17lcow074
 
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,bhuyansuprit
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130Suhani Kapoor
 
A level Digipak development Presentation
A level Digipak development PresentationA level Digipak development Presentation
A level Digipak development Presentationamedia6
 
Chapter 19_DDA_TOD Policy_First Draft 2012.pdf
Chapter 19_DDA_TOD Policy_First Draft 2012.pdfChapter 19_DDA_TOD Policy_First Draft 2012.pdf
Chapter 19_DDA_TOD Policy_First Draft 2012.pdfParomita Roy
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...Amil baba
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceanilsa9823
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Douxkojalkojal131
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case StudySophia Viganò
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制didi bibo
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
 

Recently uploaded (20)

Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptx
 
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
 
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
Abu Dhabi Call Girls O58993O4O2 Call Girls in Abu Dhabi`
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back
 
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
Bus tracking.pptx ,,,,,,,,,,,,,,,,,,,,,,,,,,
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
 
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonCheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
 
A level Digipak development Presentation
A level Digipak development PresentationA level Digipak development Presentation
A level Digipak development Presentation
 
Chapter 19_DDA_TOD Policy_First Draft 2012.pdf
Chapter 19_DDA_TOD Policy_First Draft 2012.pdfChapter 19_DDA_TOD Policy_First Draft 2012.pdf
Chapter 19_DDA_TOD Policy_First Draft 2012.pdf
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
 
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case Study
 
young call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Service
young call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Service
young call girls in Pandav nagar 🔝 9953056974 🔝 Delhi escort Service
 
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
 

MO 2020 DS Doubly Linked List 1 AB.ppt

  • 1. Programming and Data Structures Lecture #1 Doubly Linked List
  • 2. A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with next pointer and data which are there in singly linked list. 2 DOUBLY LINKED LIST: Courtesy: https://www.geeksforgeeks.org/circular-linked-list/
  • 3. Advantages of Doubly Linked Lists over singly linked list 1. A DLL can be traversed in both forward and backward direction 2. Delete operation in DLL is more efficient if pointer to the node to be deleted is given 3. 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 3
  • 4. Disadvantages of Doubly Linked Lists 1. Every node of DLL requires an extra space for a previous pointer Though it is possible to implement DLL with single pointer 2. All operations require an extra pointer previous to be maintained For example, in insertion, we need to modify previous pointers together with next pointers For example in functions for insertions at different positions, we need 1 or 2 extra steps to set previous pointer 4
  • 5. /* Node of a doubly linked list */ struct Node { int data; struct Node* next; // Pointer to next node in DLL struct Node* prev; // Pointer to previous node in DLL }; 5 Representation of DLL Node
  • 6. We are given pointer to a node as prev_node, and the new node is inserted after the given node. 6 Add a Node After a Given Node
  • 7. /* Given a node as prev_node, insert a new node after the given node */ void insertAfter(struct Node* prev_node, int new_data) { /*1. check if the given prev_node is NULL */ if (prev_node == NULL) { printf("the given previous node cannot be NULL"); return; } /* 2. allocate new node */ struct Node* new_node = (struct Node*)malloc(sizeof(struct Node)); /* 3. put in the data */ new_node->data = new_data; 7
  • 8. /* 4. Make next of new node as next of prev_node */ new_node->next = prev_node->next; /* 5. Make the next of prev_node as new_node */ prev_node->next = new_node; /* 6. Make prev_node as previous of new_node */ new_node->prev = prev_node; /* 7. Change previous of new_node's next node */ if (new_node->next != NULL) new_node->next->prev = new_node; } 8