SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Mrs.G.Chandraprabha,M.Sc.,M.Phil.,
Assistant Professor,
Department of Information Technology,
V.V.Vanniaperumal College for Women,
Virudhunagar.
Doubly Linked List is a variation of Linked list in which
navigation is possible in both ways, either forward and backward easily
as compared to Single Linked List. Following are the important terms to
understand the concept of doubly linked list.
Link − Each link of a linked list can store a data called an element.
Next − Each link of a linked list contains a link to the next link called
Next.
Prev − Each link of a linked list contains a link to the previous link
called Prev.
Linked List − A Linked List contains the connection link to the first link
called First and to the last link called Last.
Doubly Linked List
Memory Representation of a doubly linked list is shown in the
following image. Generally, doubly linked list consumes more space for every
node and therefore, causes more expansive basic operations such as insertion
and deletion. However, we can easily manipulate the elements of the list since
the list maintains pointers in both the directions (forward and backward).
In the following image, the first element of the list that is i.e. 13
stored at address 1. The head pointer points to the starting address 1. Since
this is the first element being added to the list therefore the prev of the
list contains null. The next node of the list resides at address 4 therefore the
first node contains 4 in its next pointer.
We can traverse the list in this way until we find any node
containing null or -1 in its next part.
A B C
A doubly linked listcontain three fields: an integervalue, the
link to the next node, and the link to the previous node.
Previous Data next
NULL 11 786
786
200 400
200 656 400 786 777 NULL
Doubly Linked List Representation
 Doubly Linked List contains a link element called
first and last.
 Each link carries a data field(s) and two link
fields called next and prev.
 Each link is linked with its next link using its next
link.
 Each link is linked with its previous link using its
previous link.
 The last link carries a link as null to mark the end
of the list.
 Insertion − Adds an element at the beginning of the list.
 Deletion − Deletes an element at the beginning of the list.
 Insert Last − Adds an element at the end of the list.
 Delete Last − Deletes an element from the end of the list.
 Insert After − Adds an element after an item of the list.
 Delete − Deletes an element from the list using the key.
 Display forward − Displays the complete list in a forward manner.
 Display backward − Displays the complete list in a backward
manner.
Basic Operations ON Doubly Linked List
//holds theaddress of previous node
struct node
{
int data;
node*next;
node*previous;
};
.Data .next
previous.
inf
 As in doubly linked list, each node of the list contain double
pointers therefore we have to maintain more number of pointers in doubly
linked list as compare to singly linked list.
 There are two scenarios of inserting any element into doubly
linked list. Either the list is empty or it contains at least one element.
Perform the following steps to insert a node in doubly linked list at
beginning.
 Allocate the space for the new node in the memory. This will be
done by using the following statement.
 ptr = (struct node *)malloc(sizeof(struct node));
 Check whether the list is empty or not. The list is empty if the
condition head == NULL holds
Insertion in doubly linked list at beginning
 In that case, the node will be inserted as the only node of the list and
therefore the prev and the next pointer of the node will point to NULL and
the head pointer will point to this node.
 ptr->next = NULL;
 ptr->prev=NULL;
 ptr->data=item;
 head=ptr;
 In the second scenario, the condition head == NULL become false and
the node will be inserted in beginning. The next pointer of the node will
point to the existing head pointer of the node. The prev pointer of the
existing head will point to the new node being inserted.
Insertion in doubly linked list at beginning
 This will be done by using the following statements.
 ptr->next = head;
 head→prev=ptr;
 Since, the node being inserted is the first node of the list
and therefore it must contain NULL in its prev pointer.
Hence assign null to its previous part and make the head
point to this node.
 ptr→prev =NULL
 head = ptr
Insertion in doubly linked list at beginning
Insertion in doubly linked list at beginning
 Add a node after a given node.:
We are given pointer to a node as
prev_node, and the new node is inserted after
the given node.
Insertion in doubly linked list after given Node
 The new node is always added after the last node of the given Linked List.
Since a Linked List is typically represented by the head of it, we have to
traverse the list till end and then change the next of last node to new
node.
Insertion in doubly linked list At end
Deletion in a doubly linked list can happen at
various places in the list.
 At the beginning of the doubly linked list.
 At the end of the doubly linked list.
 At a given position in the doubly linked list.
 Copy the head node in some temporary node.
 Make the second node as the head node.
 The prev pointer of the head node is referenced to NULL.
 Delete the temporary node.
 Suppose you want to delete the second node from the list.
 Start traversing the linked list from the head until the
position = 2 of the node to be deleted.
 Let the node at the position 2 of the list be temp.
 Assign the next pointer of temp to temp's previous
node's next pointer.
 Assign the temp's prev pointer to temp's next
node's prev pointer.
 Delete the temp node.
 Copy the last node to a temporary node.
 Shift the last node to the second last position.
 Make the last node's next pointer as NULL.
 Delete the temporary node.
THANK YOU

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Circular queue
Circular queueCircular queue
Circular queue
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
single linked list
single linked listsingle linked list
single linked list
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Linked list
Linked list Linked list
Linked list
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Singly link list
Singly link listSingly link list
Singly link list
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 

Ähnlich wie Doubly Linked List

Ähnlich wie Doubly Linked List (20)

Linked list
Linked listLinked list
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
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Linked list
Linked listLinked list
Linked list
 
Linked List
Linked ListLinked List
Linked List
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
 
Linked list
Linked listLinked list
Linked list
 
Linked list in DS
Linked list in DSLinked list in DS
Linked list in DS
 
Linked List
Linked ListLinked List
Linked List
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
List data structure
List data structure List data structure
List data structure
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Unit 3 dsa LINKED LIST
Unit 3 dsa LINKED LISTUnit 3 dsa LINKED LIST
Unit 3 dsa LINKED LIST
 
Data Structures(Part 1)
Data Structures(Part 1)Data Structures(Part 1)
Data Structures(Part 1)
 
linked list using c
linked list using clinked list using c
linked list using c
 

Mehr von V.V.Vanniaperumal College for Women

Mehr von V.V.Vanniaperumal College for Women (20)

Control Memory.pptx
Control Memory.pptxControl Memory.pptx
Control Memory.pptx
 
ADDRESSING MODES.pptx
ADDRESSING MODES.pptxADDRESSING MODES.pptx
ADDRESSING MODES.pptx
 
Data_Transfer&Manupulation Instructions.pptx
Data_Transfer&Manupulation Instructions.pptxData_Transfer&Manupulation Instructions.pptx
Data_Transfer&Manupulation Instructions.pptx
 
Timing & Control.pptx
Timing & Control.pptxTiming & Control.pptx
Timing & Control.pptx
 
Human Rights - 1.pptx
Human Rights - 1.pptxHuman Rights - 1.pptx
Human Rights - 1.pptx
 
Registers.pptx
Registers.pptxRegisters.pptx
Registers.pptx
 
Instruction Codes.pptx
Instruction Codes.pptxInstruction Codes.pptx
Instruction Codes.pptx
 
Features of Java.pptx
Features of Java.pptxFeatures of Java.pptx
Features of Java.pptx
 
JVM.pptx
JVM.pptxJVM.pptx
JVM.pptx
 
Constructors in JAva.pptx
Constructors in JAva.pptxConstructors in JAva.pptx
Constructors in JAva.pptx
 
IS-Crypttools.pptx
IS-Crypttools.pptxIS-Crypttools.pptx
IS-Crypttools.pptx
 
IS-Delibrate software attacks.pptx
IS-Delibrate software attacks.pptxIS-Delibrate software attacks.pptx
IS-Delibrate software attacks.pptx
 
IS-Nature of forces.ppt
IS-Nature of forces.pptIS-Nature of forces.ppt
IS-Nature of forces.ppt
 
IS-cryptograpy algorithms.pptx
IS-cryptograpy algorithms.pptxIS-cryptograpy algorithms.pptx
IS-cryptograpy algorithms.pptx
 
IS-Types of IDPSs.pptx
IS-Types of IDPSs.pptxIS-Types of IDPSs.pptx
IS-Types of IDPSs.pptx
 
IS-honeypot.pptx
IS-honeypot.pptxIS-honeypot.pptx
IS-honeypot.pptx
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
 
M-coloring.pptx
M-coloring.pptxM-coloring.pptx
M-coloring.pptx
 
storm.ppt
storm.pptstorm.ppt
storm.ppt
 
storm for RTA.pptx
storm for RTA.pptxstorm for RTA.pptx
storm for RTA.pptx
 

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Doubly Linked List

  • 1. Mrs.G.Chandraprabha,M.Sc.,M.Phil., Assistant Professor, Department of Information Technology, V.V.Vanniaperumal College for Women, Virudhunagar.
  • 2. Doubly Linked List is a variation of Linked list in which navigation is possible in both ways, either forward and backward easily as compared to Single Linked List. Following are the important terms to understand the concept of doubly linked list. Link − Each link of a linked list can store a data called an element. Next − Each link of a linked list contains a link to the next link called Next. Prev − Each link of a linked list contains a link to the previous link called Prev. Linked List − A Linked List contains the connection link to the first link called First and to the last link called Last. Doubly Linked List
  • 3. Memory Representation of a doubly linked list is shown in the following image. Generally, doubly linked list consumes more space for every node and therefore, causes more expansive basic operations such as insertion and deletion. However, we can easily manipulate the elements of the list since the list maintains pointers in both the directions (forward and backward). In the following image, the first element of the list that is i.e. 13 stored at address 1. The head pointer points to the starting address 1. Since this is the first element being added to the list therefore the prev of the list contains null. The next node of the list resides at address 4 therefore the first node contains 4 in its next pointer. We can traverse the list in this way until we find any node containing null or -1 in its next part.
  • 4.
  • 5. A B C A doubly linked listcontain three fields: an integervalue, the link to the next node, and the link to the previous node. Previous Data next NULL 11 786 786 200 400 200 656 400 786 777 NULL Doubly Linked List Representation
  • 6.  Doubly Linked List contains a link element called first and last.  Each link carries a data field(s) and two link fields called next and prev.  Each link is linked with its next link using its next link.  Each link is linked with its previous link using its previous link.  The last link carries a link as null to mark the end of the list.
  • 7.  Insertion − Adds an element at the beginning of the list.  Deletion − Deletes an element at the beginning of the list.  Insert Last − Adds an element at the end of the list.  Delete Last − Deletes an element from the end of the list.  Insert After − Adds an element after an item of the list.  Delete − Deletes an element from the list using the key.  Display forward − Displays the complete list in a forward manner.  Display backward − Displays the complete list in a backward manner. Basic Operations ON Doubly Linked List
  • 8. //holds theaddress of previous node struct node { int data; node*next; node*previous; }; .Data .next previous. inf
  • 9.  As in doubly linked list, each node of the list contain double pointers therefore we have to maintain more number of pointers in doubly linked list as compare to singly linked list.  There are two scenarios of inserting any element into doubly linked list. Either the list is empty or it contains at least one element. Perform the following steps to insert a node in doubly linked list at beginning.  Allocate the space for the new node in the memory. This will be done by using the following statement.  ptr = (struct node *)malloc(sizeof(struct node));  Check whether the list is empty or not. The list is empty if the condition head == NULL holds Insertion in doubly linked list at beginning
  • 10.  In that case, the node will be inserted as the only node of the list and therefore the prev and the next pointer of the node will point to NULL and the head pointer will point to this node.  ptr->next = NULL;  ptr->prev=NULL;  ptr->data=item;  head=ptr;  In the second scenario, the condition head == NULL become false and the node will be inserted in beginning. The next pointer of the node will point to the existing head pointer of the node. The prev pointer of the existing head will point to the new node being inserted. Insertion in doubly linked list at beginning
  • 11.  This will be done by using the following statements.  ptr->next = head;  head→prev=ptr;  Since, the node being inserted is the first node of the list and therefore it must contain NULL in its prev pointer. Hence assign null to its previous part and make the head point to this node.  ptr→prev =NULL  head = ptr Insertion in doubly linked list at beginning
  • 12. Insertion in doubly linked list at beginning
  • 13.  Add a node after a given node.: We are given pointer to a node as prev_node, and the new node is inserted after the given node. Insertion in doubly linked list after given Node
  • 14.  The new node is always added after the last node of the given Linked List. Since a Linked List is typically represented by the head of it, we have to traverse the list till end and then change the next of last node to new node. Insertion in doubly linked list At end
  • 15. Deletion in a doubly linked list can happen at various places in the list.  At the beginning of the doubly linked list.  At the end of the doubly linked list.  At a given position in the doubly linked list.
  • 16.  Copy the head node in some temporary node.  Make the second node as the head node.  The prev pointer of the head node is referenced to NULL.  Delete the temporary node.
  • 17.  Suppose you want to delete the second node from the list.  Start traversing the linked list from the head until the position = 2 of the node to be deleted.  Let the node at the position 2 of the list be temp.  Assign the next pointer of temp to temp's previous node's next pointer.  Assign the temp's prev pointer to temp's next node's prev pointer.  Delete the temp node.
  • 18.
  • 19.  Copy the last node to a temporary node.  Shift the last node to the second last position.  Make the last node's next pointer as NULL.  Delete the temporary node.