SlideShare a Scribd company logo
1 of 19
Double Linked lists
Double Linked list
• Single linked list= one-way list
– List can be traversed in one direction only
• Double linked list= Two-way list
– List can be traversed in two directions
• A two- way list is a linear collection of data elements
called nodes where each node N is divided in to three
parts
– Data field contains the data of N
– LLINK field contains the pointer to the preceding Node in the
list
– RLINK field contains the pointer to the next node in the list
Double Linked list
– Data field contains the data of N
– Rlink field contains the pointer to the next Node in the list
– Llink field contains the pointer to the preceding node in the list
Data Rlink
Llink
Dr Zeinab Eid 4
Double Linked List
• Each node contain:
• Element/data
• link to the previous node
• link to the next node
llink rlink
data
10 20 30 40 null
head
node
Node creation
Algorithm: Struct Node
1. Start
2. Declare int data, Node *llink, Node *rlink
3. exit
Data null
null
Node creation
struct node
{
int data; //data item in node
struct node *llink,*rlink; // reference to leftt & right node
};
data rlink
llink
Insertion
• In a double linked list, a new node can be inserted:
1. At the first location
2. At the last location
3. At any position
Insertion at 1st location
1. head-> llink=temp
2. temp-> rlink=head
3. head=temp
temp
llink data rlink
20
head
10
null 30 null
5
null
Insertion in the front
1. Set ptr=head
2. Create a new node temp //struct node *temp=(struct node*)
malloc(sizeof(struct node));
3. If(temp!= NULL)
4. Read ‘item’ to be inserted
temp->data =item
5. head->llink=temp
6. temp-> rlink=head
7. head=temp
8. Else
9. Print “Unable to allocate memory”
Insertion at last location
1. ptr->rlink=temp
2. temp->llink=ptr
20
head
10
null 30 null
35 null
null
Prev data next
temp
ptr
Insertion at last location
1. Set ptr=head
2. Create a new node temp and read the element “item” to be inserted
3. temp->data= item
4. While(ptr-rlink!=null)
5. ptr=ptr->rlink
6 ptr->rlink=temp
7. temp->llink=ptr
20
head
10
null 30 null
35 null
null
Prev data next
temp
ptr
Insertion- after an element key
20
head
10
null 30 null
25
Prev data next
temp
ptr
Insert 25 after 20
Insertion- after an element key
1. Read value key after which new node is to be inserted
2. Create temp and read element to be inserted
3. Set ptr=head
4. Repeat while( ptr->data!=key)
5. ptr=ptr->rlink
6. If(ptr-> data==key)
6. temp->rlink=ptr->rlink //7. set ptr1=ptr->rlink
7. ptr->rlink->llink= temp ptr1->llink=temp
8. temp->llink=ptr
9. ptr->rlink=temp
Deletion
• In a double linked list, an element can be
deleted:
1. From the 1st location
2. From the last location
3. From intermediate location
Deletion- from 1st location
• Delete node 10
1. head=head->rlink
2. head->llink= null
20
head
10
null null 30 null
Deletion- from last location
• Delete node 30
1. Set ptr=head
2. While(ptr->rlink!=null)
3. ptr=ptr->rlink
4. Set ptr1=ptr->llink
5. ptr1->rlink=null
6. free(ptr)
20 null
head
10
null 30 null
ptr
ptr1
Deletion- from intermediate location
• Delete node key=20
1. Set ptr=head
2. Repeat While (ptr-> data!=key)&& ptr->rlink!=null)
3. ptr=ptr->rlink
4. If(ptr->data=key)
5. ptr1=ptr->llink
6. ptr2=ptr->rlink
7. ptr1->rlink=ptr2
8. ptr2->llink=ptr1
9. free(ptr)
20
head
10
null 30 null
ptr
ptr1 ptr2
Circular double linked list
• The advantages of both double linked list and circular
linked list are incorporated into another type of list
structure called circular double linked list
20 null
10 30
head
Circular double linked list
• Here rlink of last node and llink of the first node points
back to the head node.
• Llink of head node contain the address of leftmost node
• Rlink of head node contain the address of the rightmost
node
• Empty circular double linked list is represented as
• Here both llink and rlink of head points to itself

More Related Content

Similar to Double linked list.pptx

Similar to Double linked list.pptx (20)

Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdf
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 

Recently uploaded

Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
BalamuruganV28
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
IJECEIAES
 

Recently uploaded (20)

Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney Uni
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 

Double linked list.pptx

  • 2. Double Linked list • Single linked list= one-way list – List can be traversed in one direction only • Double linked list= Two-way list – List can be traversed in two directions • A two- way list is a linear collection of data elements called nodes where each node N is divided in to three parts – Data field contains the data of N – LLINK field contains the pointer to the preceding Node in the list – RLINK field contains the pointer to the next node in the list
  • 3. Double Linked list – Data field contains the data of N – Rlink field contains the pointer to the next Node in the list – Llink field contains the pointer to the preceding node in the list Data Rlink Llink
  • 4. Dr Zeinab Eid 4 Double Linked List • Each node contain: • Element/data • link to the previous node • link to the next node llink rlink data 10 20 30 40 null head node
  • 5. Node creation Algorithm: Struct Node 1. Start 2. Declare int data, Node *llink, Node *rlink 3. exit Data null null
  • 6. Node creation struct node { int data; //data item in node struct node *llink,*rlink; // reference to leftt & right node }; data rlink llink
  • 7. Insertion • In a double linked list, a new node can be inserted: 1. At the first location 2. At the last location 3. At any position
  • 8. Insertion at 1st location 1. head-> llink=temp 2. temp-> rlink=head 3. head=temp temp llink data rlink 20 head 10 null 30 null 5 null
  • 9. Insertion in the front 1. Set ptr=head 2. Create a new node temp //struct node *temp=(struct node*) malloc(sizeof(struct node)); 3. If(temp!= NULL) 4. Read ‘item’ to be inserted temp->data =item 5. head->llink=temp 6. temp-> rlink=head 7. head=temp 8. Else 9. Print “Unable to allocate memory”
  • 10. Insertion at last location 1. ptr->rlink=temp 2. temp->llink=ptr 20 head 10 null 30 null 35 null null Prev data next temp ptr
  • 11. Insertion at last location 1. Set ptr=head 2. Create a new node temp and read the element “item” to be inserted 3. temp->data= item 4. While(ptr-rlink!=null) 5. ptr=ptr->rlink 6 ptr->rlink=temp 7. temp->llink=ptr 20 head 10 null 30 null 35 null null Prev data next temp ptr
  • 12. Insertion- after an element key 20 head 10 null 30 null 25 Prev data next temp ptr Insert 25 after 20
  • 13. Insertion- after an element key 1. Read value key after which new node is to be inserted 2. Create temp and read element to be inserted 3. Set ptr=head 4. Repeat while( ptr->data!=key) 5. ptr=ptr->rlink 6. If(ptr-> data==key) 6. temp->rlink=ptr->rlink //7. set ptr1=ptr->rlink 7. ptr->rlink->llink= temp ptr1->llink=temp 8. temp->llink=ptr 9. ptr->rlink=temp
  • 14. Deletion • In a double linked list, an element can be deleted: 1. From the 1st location 2. From the last location 3. From intermediate location
  • 15. Deletion- from 1st location • Delete node 10 1. head=head->rlink 2. head->llink= null 20 head 10 null null 30 null
  • 16. Deletion- from last location • Delete node 30 1. Set ptr=head 2. While(ptr->rlink!=null) 3. ptr=ptr->rlink 4. Set ptr1=ptr->llink 5. ptr1->rlink=null 6. free(ptr) 20 null head 10 null 30 null ptr ptr1
  • 17. Deletion- from intermediate location • Delete node key=20 1. Set ptr=head 2. Repeat While (ptr-> data!=key)&& ptr->rlink!=null) 3. ptr=ptr->rlink 4. If(ptr->data=key) 5. ptr1=ptr->llink 6. ptr2=ptr->rlink 7. ptr1->rlink=ptr2 8. ptr2->llink=ptr1 9. free(ptr) 20 head 10 null 30 null ptr ptr1 ptr2
  • 18. Circular double linked list • The advantages of both double linked list and circular linked list are incorporated into another type of list structure called circular double linked list 20 null 10 30 head
  • 19. Circular double linked list • Here rlink of last node and llink of the first node points back to the head node. • Llink of head node contain the address of leftmost node • Rlink of head node contain the address of the rightmost node • Empty circular double linked list is represented as • Here both llink and rlink of head points to itself