SlideShare a Scribd company logo
Data Structures

  Doubly Link List
Problem ….
   The member function deleteFromTail() of
    singly linked list indicates a problem
    inherent to singly linked lists.
   The nodes in singly linked lists contain only
    pointers to the successors;
   Therefore there is no immediate access to
    the predecessors.
   For this reason, deleteFromTail() was
    implemented with a loop allowed us to find
    the predecessor of tail.
   But the problem is
Problem ….
 We have to scan the entire list to stop
  right in front of the tail to delete it.
 For long lists and for frequent
  executions of deleteFromTail(), this
  may be an impediment to swift list
  processing.
 Is there any way to avoid this
  effort?
Solution
 We redefine the linked list so that
 Each node in a list has two pointers,

  one to the successor and one to the
  predecessor.
 A list of this type is called a doubly

  linked list.
       a      b         c          d 

head                                 tail
Doubly Linked List
             Operations
    The common operations on doubly linked lists are:
1.   AddToDLLHead(x) Inserts element x in front of the
     doubly linked list .
2.   AddToDLLTail(x) Inserts element x at the end of
     the doubly linked list.
3.   DeleteFromDLLHead() Deletes the first element of
     the doubly linked list.
4.   DeleteFromDLLTail() Deletes the last element of
     the doubly linked list.
5.   DLLDelete(x) Deletes the node of value x from the
     doubly linked list.
6.   DLLFind(x) Find the entry x in the doubly linked
     list.
7.   DLLprint() prints the contents of the doubly linked
     list.
8.   And so on i.e.as many operations as you
     required
Doubly Linked List
Operations AddToDLLTail(x)
   Two cases must be considered to add the
    node at the end of doubly linked list.

    1. Either we are creating the first node of the
       doubly linked list or

    1. We are inserting the node at the end of an
       existing doubly linked list.
Doubly Linked List
 Operations AddToDLLTail(x)
    First Case: Creating first node of a doubly
     linked list.
    We follow the following steps to create the first
     node of the doubly linked list.
1.   Check the value of the head of the doubly linked
     list.
        If this value is null it means we are creating the first node
        of the doubly linked list.
2.   An empty node of doubly linked list is created.

        It is empty in the sense that the program performing
        insertion does not assign any values to the data members
        of the node.
Doubly Linked List
 Operations AddToDLLTail(x)
3.   The node's info member is initialized to a particular
     value.
                           7

4. Since it is the only node of the doubly linked list
   therefore its next and previous members will be
   initialized to null.
                          7   

5. Since it is the only node of the doubly linked list
   therefore both head and tail points to this node of the
   doubly linked list.             7 
                           head                tail
Doubly Linked List
 Operations AddToDLLTail(x)
    Second Case: Inserting node at the
     end of an existing doubly linked
     list.
    We follow the following steps to insert
     the node at the end of an existing
     doubly linked list.
1.   Check the value of the head of the doubly
     list.
       If this value is not null it means doubly linked
       list already exists and we insert the node at the
       end of an existing doubly linked list.
                                7 
                        head               tail
Doubly Linked List
 Operations AddToDLLTail(x)
2.    An empty node of doubly linked list is
      created.

         It is empty in the sense that the program
         performing insertion does not assign any
         values to the data members of the node.
              7 
     head                tail
Doubly Linked List
 Operations AddToDLLTail(x)
3.    The node's info member is initialized to a particular value.

                    7                       8       
     head                        tail

4.    Because the node is being included at the end of the doubly
      linked list, the next member is set to null.
5.    Set the previous member of the new node to the value of tail,
      so that this member points to the last node in the list.

6.    Set the next member of the tail to point to the new node

                        7                        8       
      head
                                   tail
Doubly Linked List
 Operations AddToDLLTail(x)
7.   Now, the new node should become the last node of the
     linked list, therefore tail is set to point to the new node.


                     7                          8       
     head                     tail

                         7                          8       
       head                                                      tail
Doubly Linked List Operations
       DeleteFromDLLTail(x)
    Two cases must be considered to
     delete the node from the end of a
     linked list.

    1. Either a doubly linked list has only one
       node or



    1. A doubly linked list has more than one
       nodes.
Doubly Linked List Operations
        DeleteFromDLLTail(x)
     First Case: Linked List has only
      one node:
     We follow the following steps to
      handle this case:
1.    Check the values of the pointer
      variables head and tail.
        If both points to the same node, means
        doubly linked list has only one node.
                                7   
                      head               tail
Doubly Linked List Operations
        DeleteFromDLLTail(x)
2.    Set both head and tail pointers to
      null and return back the memory
      occupied by the node to the system.
Doubly Linked List Operations
         DeleteFromDLLTail(x)
      Second Case: Doubly Linked List
       has more than one nodes:
      We follow the following steps to
       handle this case:
 1.    Check the values of the pointer
       variables head and tail.
           If both points to the different nodes,
           means linked list has more than one
           nodes.
           7          8          9          4   
head                                                 tail
Doubly Linked List Operations
         DeleteFromDLLTail(x)
 2.    Set the variable tail to its
       predecessor.
          7        8          9      4   
head                                          tail

          7        8          9      4   
head
                               tail
Doubly Linked List Operations
         DeleteFromDLLTail(x)
 3.     Remove the last node of the doubly
        linked list, i.e. node next to the node
        pointed by tail pointer.
               7    8         9        4   
head
                               tail

                7    8         9
 head
                                tail
Doubly Linked List Operations
        DeleteFromDLLTail(x)
4.     The next of the tail node is a
       dangling reference; therefore next is
       set to null.
           7       8        9
head
                             tail

           7       8         9      
head
                              tail
Implementation of
           Doubly Linked List
template<class T>
class DLLNode {
public:
   T info;
   DLLNode *next, *prev;
   DLLNode() {
        next = prev = 0;
   }
   DLLNode(T el, Node *n = 0, Node *p = 0) {
        info = el;
        next = n;
        prev = p;
   }
};
Implementation of
              Doubly Linked List
template<class T>
class DoublyLInkedList {
private:
        DLLNode <T> *head, *tail;
Public:
     DoublyLinkedList(){
       head = tail =0;
     }
     void addToDLLTail(const T&)
     void deleteFromDLLTail();
     ……………………………..

};
Implementation of
                       Doubly Linked List
       template<class T>
       void DoublyLinkedList<T>:: addToDLLTail(const T& el)
       { if(head == 0)                     //List is empty
                                                                   7 
            head = tail = new DLLNode<T>(el); head                           tail
         else               // Insert node at the end of the list
         { tail = new DLLNode<T>(e1, 0, tail);
             tail -> prev -> next = tail
               }
       }

                  7                   8                     9   
head                                              tail                    tail
Implementation of
                   Doubly Linked List
template<class T>
void DoublyLinkedList<T>:: deleteFromDLLTail()
{ if(head != 0)                      //List not empty
    if(head == tail) { //If only one node in the list
           delete head;           head = tail = 0; }                7 
        else // more then one nodes in the list       head                    tail
        {
             tail = tail -> prev;
             delete tail -> next;
            tail -> next = 0;
           }
 }            7                      8                         9   
head                                            tail                       tail
Lab Exercise
    Implement the template class for doubly
     linked list with following member functions.
1.   A function which inserts node in front of
     doubly linked list.
2.   A function which inserts node at the end of
     doubly linked list
3.   A function which removes a node from the
     front of doubly linked list.
4.   A function which removes a node from the
     end of doubly linked list.
Lab Exercise
5.   A function which removes a node of
     particular value from doubly linked
     list.
6.   A function which finds a node of
     particular value from doubly linked
     list.
7.   A function which prints the contents of
     doubly linked list.
Ad

More Related Content

What's hot (20)

Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
Khulna University of Engineering & Tecnology
 
linked list
linked listlinked list
linked list
Shaista Qadir
 
Singly link list
Singly link listSingly link list
Singly link list
Rojin Khadka
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
maamir farooq
 
Linked list
Linked listLinked list
Linked list
VONI
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
linked list
linked list linked list
linked list
Narendra Chauhan
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
Muhazzab Chouhadry
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
naymulhaque
 
Linked list
Linked listLinked list
Linked list
eShikshak
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
Prof Ansari
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
Kumar
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
Teksify
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Link list
Link listLink list
Link list
Ravi Gautam
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
maamir farooq
 
Linked list
Linked listLinked list
Linked list
VONI
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
Muhazzab Chouhadry
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
Prof Ansari
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
Kumar
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
Teksify
 

Viewers also liked (8)

LINKED LISTS
LINKED LISTSLINKED LISTS
LINKED LISTS
Dhrthi Nanda
 
Car Parking System (Singly linked list )
Car Parking System (Singly linked list ) Car Parking System (Singly linked list )
Car Parking System (Singly linked list )
S. M. Shakib Limon
 
Singly linked lists
Singly linked listsSingly linked lists
Singly linked lists
Jonghoon Park
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animation
Lovelyn Rose
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Data structures1
Data structures1Data structures1
Data structures1
Parthipan Parthi
 
Lecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsLecture 2 data structures and algorithms
Lecture 2 data structures and algorithms
Aakash deep Singhal
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Car Parking System (Singly linked list )
Car Parking System (Singly linked list ) Car Parking System (Singly linked list )
Car Parking System (Singly linked list )
S. M. Shakib Limon
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animation
Lovelyn Rose
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Lecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsLecture 2 data structures and algorithms
Lecture 2 data structures and algorithms
Aakash deep Singhal
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Ad

Similar to Data Structure Lecture 6 (20)

Data Structure Lecture 7
Data Structure Lecture 7Data Structure Lecture 7
Data Structure Lecture 7
Teksify
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
ASADAHMAD811380
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Linked Lists, Single Linked list and its operations
Linked Lists, Single Linked list and its operationsLinked Lists, Single Linked list and its operations
Linked Lists, Single Linked list and its operations
BackiyalakshmiVenkat
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
sauravmanwanicp
 
Use the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdfUse the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
KylaMaeGarcia1
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
MatthPYNashd
 
LinkedList1LinkedList1LinkedList1111.pdf
LinkedList1LinkedList1LinkedList1111.pdfLinkedList1LinkedList1LinkedList1111.pdf
LinkedList1LinkedList1LinkedList1111.pdf
timoemin50
 
Ds lists
Ds listsDs lists
Ds lists
Dzinh Tuong
 
3.ppt
3.ppt3.ppt
3.ppt
ArifKamal36
 
3.ppt
3.ppt3.ppt
3.ppt
ArifKamal36
 
Data Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptxData Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptx
JoannahClaireAlforqu
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
edgar6wallace88877
 
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
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
SSE_AndyLi
 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.pptLINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
Data Structure Lecture 7
Data Structure Lecture 7Data Structure Lecture 7
Data Structure Lecture 7
Teksify
 
Linked Lists, Single Linked list and its operations
Linked Lists, Single Linked list and its operationsLinked Lists, Single Linked list and its operations
Linked Lists, Single Linked list and its operations
BackiyalakshmiVenkat
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
sauravmanwanicp
 
Use the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdfUse the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
KylaMaeGarcia1
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
MatthPYNashd
 
LinkedList1LinkedList1LinkedList1111.pdf
LinkedList1LinkedList1LinkedList1111.pdfLinkedList1LinkedList1LinkedList1111.pdf
LinkedList1LinkedList1LinkedList1111.pdf
timoemin50
 
Data Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptxData Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptx
JoannahClaireAlforqu
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
edgar6wallace88877
 
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
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
SSE_AndyLi
 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.pptLINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
Ad

More from Teksify (10)

HCTE C&C08(TDM)
HCTE C&C08(TDM) HCTE C&C08(TDM)
HCTE C&C08(TDM)
Teksify
 
Data Structure Lecture 4
Data Structure Lecture 4Data Structure Lecture 4
Data Structure Lecture 4
Teksify
 
Data Structure Lecture 3
Data Structure Lecture 3Data Structure Lecture 3
Data Structure Lecture 3
Teksify
 
Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2
Teksify
 
data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1
Teksify
 
Ch3
Ch3Ch3
Ch3
Teksify
 
Ch1 2
Ch1 2Ch1 2
Ch1 2
Teksify
 
Variable power supply
Variable power supplyVariable power supply
Variable power supply
Teksify
 
Use of rib tool in pro e
Use of rib tool in pro eUse of rib tool in pro e
Use of rib tool in pro e
Teksify
 
Make lens of mobile by pro e
Make lens of mobile by pro eMake lens of mobile by pro e
Make lens of mobile by pro e
Teksify
 
HCTE C&C08(TDM)
HCTE C&C08(TDM) HCTE C&C08(TDM)
HCTE C&C08(TDM)
Teksify
 
Data Structure Lecture 4
Data Structure Lecture 4Data Structure Lecture 4
Data Structure Lecture 4
Teksify
 
Data Structure Lecture 3
Data Structure Lecture 3Data Structure Lecture 3
Data Structure Lecture 3
Teksify
 
Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2
Teksify
 
data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1
Teksify
 
Variable power supply
Variable power supplyVariable power supply
Variable power supply
Teksify
 
Use of rib tool in pro e
Use of rib tool in pro eUse of rib tool in pro e
Use of rib tool in pro e
Teksify
 
Make lens of mobile by pro e
Make lens of mobile by pro eMake lens of mobile by pro e
Make lens of mobile by pro e
Teksify
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdfIPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
Quiz Club of PSG College of Arts & Science
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
materi 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblrmateri 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblr
fatikhatunnajikhah1
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERSIMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
rajaselviazhagiri1
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Conditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture SlideConditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture Slide
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Dastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptxDastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptx
omorfaruqkazi
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
114P_English.pdf114P_English.pdf114P_English.pdf
114P_English.pdf114P_English.pdf114P_English.pdf114P_English.pdf114P_English.pdf114P_English.pdf
114P_English.pdf114P_English.pdf114P_English.pdf
paulinelee52
 
How to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 SalesHow to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 Sales
Celine George
 
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic SuccessAerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
online college homework help
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
materi 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblrmateri 3D Augmented Reality dengan assemblr
materi 3D Augmented Reality dengan assemblr
fatikhatunnajikhah1
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERSIMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
rajaselviazhagiri1
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Dastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptxDastur_ul_Amal under Jahangir Key Features.pptx
Dastur_ul_Amal under Jahangir Key Features.pptx
omorfaruqkazi
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
114P_English.pdf114P_English.pdf114P_English.pdf
114P_English.pdf114P_English.pdf114P_English.pdf114P_English.pdf114P_English.pdf114P_English.pdf
114P_English.pdf114P_English.pdf114P_English.pdf
paulinelee52
 
How to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 SalesHow to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 Sales
Celine George
 
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic SuccessAerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
online college homework help
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 

Data Structure Lecture 6

  • 1. Data Structures Doubly Link List
  • 2. Problem ….  The member function deleteFromTail() of singly linked list indicates a problem inherent to singly linked lists.  The nodes in singly linked lists contain only pointers to the successors;  Therefore there is no immediate access to the predecessors.  For this reason, deleteFromTail() was implemented with a loop allowed us to find the predecessor of tail.  But the problem is
  • 3. Problem ….  We have to scan the entire list to stop right in front of the tail to delete it.  For long lists and for frequent executions of deleteFromTail(), this may be an impediment to swift list processing.  Is there any way to avoid this effort?
  • 4. Solution  We redefine the linked list so that  Each node in a list has two pointers, one to the successor and one to the predecessor.  A list of this type is called a doubly linked list. a b c d head tail
  • 5. Doubly Linked List Operations  The common operations on doubly linked lists are: 1. AddToDLLHead(x) Inserts element x in front of the doubly linked list . 2. AddToDLLTail(x) Inserts element x at the end of the doubly linked list. 3. DeleteFromDLLHead() Deletes the first element of the doubly linked list. 4. DeleteFromDLLTail() Deletes the last element of the doubly linked list. 5. DLLDelete(x) Deletes the node of value x from the doubly linked list. 6. DLLFind(x) Find the entry x in the doubly linked list. 7. DLLprint() prints the contents of the doubly linked list. 8. And so on i.e.as many operations as you required
  • 6. Doubly Linked List Operations AddToDLLTail(x)  Two cases must be considered to add the node at the end of doubly linked list. 1. Either we are creating the first node of the doubly linked list or 1. We are inserting the node at the end of an existing doubly linked list.
  • 7. Doubly Linked List Operations AddToDLLTail(x)  First Case: Creating first node of a doubly linked list.  We follow the following steps to create the first node of the doubly linked list. 1. Check the value of the head of the doubly linked list. If this value is null it means we are creating the first node of the doubly linked list. 2. An empty node of doubly linked list is created. It is empty in the sense that the program performing insertion does not assign any values to the data members of the node.
  • 8. Doubly Linked List Operations AddToDLLTail(x) 3. The node's info member is initialized to a particular value. 7 4. Since it is the only node of the doubly linked list therefore its next and previous members will be initialized to null. 7 5. Since it is the only node of the doubly linked list therefore both head and tail points to this node of the doubly linked list. 7 head tail
  • 9. Doubly Linked List Operations AddToDLLTail(x)  Second Case: Inserting node at the end of an existing doubly linked list.  We follow the following steps to insert the node at the end of an existing doubly linked list. 1. Check the value of the head of the doubly list. If this value is not null it means doubly linked list already exists and we insert the node at the end of an existing doubly linked list. 7 head tail
  • 10. Doubly Linked List Operations AddToDLLTail(x) 2. An empty node of doubly linked list is created. It is empty in the sense that the program performing insertion does not assign any values to the data members of the node. 7 head tail
  • 11. Doubly Linked List Operations AddToDLLTail(x) 3. The node's info member is initialized to a particular value. 7 8 head tail 4. Because the node is being included at the end of the doubly linked list, the next member is set to null. 5. Set the previous member of the new node to the value of tail, so that this member points to the last node in the list. 6. Set the next member of the tail to point to the new node 7 8 head tail
  • 12. Doubly Linked List Operations AddToDLLTail(x) 7. Now, the new node should become the last node of the linked list, therefore tail is set to point to the new node. 7 8 head tail 7 8 head tail
  • 13. Doubly Linked List Operations DeleteFromDLLTail(x)  Two cases must be considered to delete the node from the end of a linked list. 1. Either a doubly linked list has only one node or 1. A doubly linked list has more than one nodes.
  • 14. Doubly Linked List Operations DeleteFromDLLTail(x)  First Case: Linked List has only one node:  We follow the following steps to handle this case: 1. Check the values of the pointer variables head and tail. If both points to the same node, means doubly linked list has only one node. 7 head tail
  • 15. Doubly Linked List Operations DeleteFromDLLTail(x) 2. Set both head and tail pointers to null and return back the memory occupied by the node to the system.
  • 16. Doubly Linked List Operations DeleteFromDLLTail(x)  Second Case: Doubly Linked List has more than one nodes:  We follow the following steps to handle this case: 1. Check the values of the pointer variables head and tail. If both points to the different nodes, means linked list has more than one nodes. 7 8 9 4 head tail
  • 17. Doubly Linked List Operations DeleteFromDLLTail(x) 2. Set the variable tail to its predecessor. 7 8 9 4 head tail 7 8 9 4 head tail
  • 18. Doubly Linked List Operations DeleteFromDLLTail(x) 3. Remove the last node of the doubly linked list, i.e. node next to the node pointed by tail pointer. 7 8 9 4 head tail 7 8 9 head tail
  • 19. Doubly Linked List Operations DeleteFromDLLTail(x) 4. The next of the tail node is a dangling reference; therefore next is set to null. 7 8 9 head tail 7 8 9 head tail
  • 20. Implementation of Doubly Linked List template<class T> class DLLNode { public: T info; DLLNode *next, *prev; DLLNode() { next = prev = 0; } DLLNode(T el, Node *n = 0, Node *p = 0) { info = el; next = n; prev = p; } };
  • 21. Implementation of Doubly Linked List template<class T> class DoublyLInkedList { private: DLLNode <T> *head, *tail; Public: DoublyLinkedList(){ head = tail =0; } void addToDLLTail(const T&) void deleteFromDLLTail(); …………………………….. };
  • 22. Implementation of Doubly Linked List template<class T> void DoublyLinkedList<T>:: addToDLLTail(const T& el) { if(head == 0) //List is empty 7 head = tail = new DLLNode<T>(el); head tail else // Insert node at the end of the list { tail = new DLLNode<T>(e1, 0, tail); tail -> prev -> next = tail } } 7 8 9 head tail tail
  • 23. Implementation of Doubly Linked List template<class T> void DoublyLinkedList<T>:: deleteFromDLLTail() { if(head != 0) //List not empty if(head == tail) { //If only one node in the list delete head; head = tail = 0; } 7 else // more then one nodes in the list head tail { tail = tail -> prev; delete tail -> next; tail -> next = 0; } } 7 8 9 head tail tail
  • 24. Lab Exercise  Implement the template class for doubly linked list with following member functions. 1. A function which inserts node in front of doubly linked list. 2. A function which inserts node at the end of doubly linked list 3. A function which removes a node from the front of doubly linked list. 4. A function which removes a node from the end of doubly linked list.
  • 25. Lab Exercise 5. A function which removes a node of particular value from doubly linked list. 6. A function which finds a node of particular value from doubly linked list. 7. A function which prints the contents of doubly linked list.
  翻译: