SlideShare a Scribd company logo
1 of 3
Download to read offline
4 April, 2008
                                 Doubly Linked List




Doubly-linked list(DLL) is a more sophisticated kind of linked list. In DLL, each
node has two links: one points to previous node and one points to next node. The
previous link of first node in the list points to a Null and the next link of last node
points to Null.


The code of the Double Linked List class is as follows:

class Node{
       Item item;
       Node prev, next;

       /* Constructors of Node Class */
       Node(){
              this(null, null, null);
       }

       Node(Item t){
              this(t, null, null);
       }

        Node(Item t, node next, node prev){
                this.item = t;
                this.next = next;
                this.prev = prev;
        }
} // End of class Node


class DLL{
       private Node head = null;

       /* Methods to add an element in the list */
       public void addElementFront(Item t){
              Node n = new Node(t, null, head);
if(head!=null)
              head.prev = n;
       head = nl
}




private void addElementAfter(Node n, Item t){
        Node newN = new Node(t, n, n.next);
        if(n.next != null)
                 newN.next.prev = newN;
        n.next = newN;
} // This method is made private to avoid the external access to Node n
public void addElementRear(Item t){
        Node n = head;
        if(n == null){
                 addElementFront(t);
                 return;
        } //If the list is empty, then we can front and rear element after 
                 addition of element will be same

       // Traverse through the list till last element is encountered
       while(n.next != null)
               n = n.next;

       // Now add element after the current last element of list
       addElementAfter(n, t);
}




/* Method to delete an element from the list */
private void deleteElement(Node n){
        if(n.prev != null){
n.prev.next = n.next;
               if(n.next != null)
                       n.next.prev = n.prev;
       }
} //End of class DLL



       Compared to Singly Linked List, in Doubly Linked List, one has to update
more pointers, but less information is required as one can use previous links to
observer preceding elements in the list.


Circular Linked List:
         Circular Linked List is a special type of linked list in which all the nodes are
linked in continuous circle. Circular list can be Singly or doubly linked list. Note that,
there are no Nulls in Circular Linked Lists. In these type of lists, elements can be
added to the back of the list and removed from the front in constant time.
         Both types of circularly-linked lists benefit from the ability to traverse the full
list beginning at any given node. This avoids the necessity of storing first Node and
last node, but we need a special representation for the empty list, such as a last node
variable which points to some node in the list or is null if it's empty. This
representation significantly simplifies adding and removing nodes with a non-empty
list, but empty lists are then a special case.
         Circular linked lists are most useful for describing naturally circular structures,
and have the advantage of being able to traverse the list starting at any point. They
also allow quick access to the first and last records through a single pointer (the
address of the last element).




Typecasting refers to changing an entity of one data type into another.
e.g.  byte b;
      (int) b;

In object-oriented programming, Inheritance is a way to form new classes using
classes that have already been defined. The new classes, known as derived classes,
take over (or inherit) attributes and behavior of the pre-existing classes, which are
referred to as base classes. It is intended to help reuse existing code with little or no
modification.

In the next lecture, we will understand the Object Oriented concepts like Class
Inheritance and will look at some examples of Type Casting.

More Related Content

What's hot

Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.pptTirthika Bandi
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queueSrajan Shukla
 
Linked list
Linked listLinked list
Linked listVONI
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and searchEstiak Khan
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6Teksify
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)shah alom
 

What's hot (20)

Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Linked list
Linked listLinked list
Linked list
 
Singly link list
Singly link listSingly link list
Singly link list
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6
 
Link List
Link ListLink List
Link List
 
linked list
linked list linked 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 lists 1
Linked lists 1Linked lists 1
Linked lists 1
 
Linked List
Linked ListLinked List
Linked List
 
Linked lists
Linked listsLinked lists
Linked lists
 
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
 
Linked list
Linked listLinked list
Linked list
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
 

Viewers also liked

Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked ListSayantan Sur
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked listRoshan Chaudhary
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data StructuresAdarsh Patel
 
Double linked list
Double linked listDouble linked list
Double linked listSayantan Sur
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and AlgorithmsPierre Vigneras
 

Viewers also liked (10)

Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and Algorithms
 
Linked list
Linked listLinked list
Linked list
 

Similar to Doubly Link List

1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdffms12345
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversalkasthurimukila
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data StructureMeghaj Mallick
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1DrSudeshna
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructuresNguync91368
 

Similar to Doubly Link List (20)

1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Linked list
Linked list Linked list
Linked list
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdf
 
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
Linked ListLinked List
Linked List
 
Linked list
Linked listLinked list
Linked list
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Linked list
Linked listLinked list
Linked list
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data Structure
 
Link list assi
Link list assiLink list assi
Link list assi
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
Data structures2
Data structures2Data structures2
Data structures2
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 

Recently uploaded

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

Doubly Link List

  • 1. 4 April, 2008 Doubly Linked List Doubly-linked list(DLL) is a more sophisticated kind of linked list. In DLL, each node has two links: one points to previous node and one points to next node. The previous link of first node in the list points to a Null and the next link of last node points to Null. The code of the Double Linked List class is as follows: class Node{ Item item; Node prev, next; /* Constructors of Node Class */ Node(){ this(null, null, null); } Node(Item t){ this(t, null, null); } Node(Item t, node next, node prev){ this.item = t; this.next = next; this.prev = prev; } } // End of class Node class DLL{ private Node head = null; /* Methods to add an element in the list */ public void addElementFront(Item t){ Node n = new Node(t, null, head);
  • 2. if(head!=null) head.prev = n; head = nl } private void addElementAfter(Node n, Item t){ Node newN = new Node(t, n, n.next); if(n.next != null) newN.next.prev = newN; n.next = newN; } // This method is made private to avoid the external access to Node n public void addElementRear(Item t){ Node n = head; if(n == null){ addElementFront(t); return; } //If the list is empty, then we can front and rear element after addition of element will be same // Traverse through the list till last element is encountered while(n.next != null) n = n.next; // Now add element after the current last element of list addElementAfter(n, t); } /* Method to delete an element from the list */ private void deleteElement(Node n){ if(n.prev != null){
  • 3. n.prev.next = n.next; if(n.next != null) n.next.prev = n.prev; } } //End of class DLL Compared to Singly Linked List, in Doubly Linked List, one has to update more pointers, but less information is required as one can use previous links to observer preceding elements in the list. Circular Linked List: Circular Linked List is a special type of linked list in which all the nodes are linked in continuous circle. Circular list can be Singly or doubly linked list. Note that, there are no Nulls in Circular Linked Lists. In these type of lists, elements can be added to the back of the list and removed from the front in constant time. Both types of circularly-linked lists benefit from the ability to traverse the full list beginning at any given node. This avoids the necessity of storing first Node and last node, but we need a special representation for the empty list, such as a last node variable which points to some node in the list or is null if it's empty. This representation significantly simplifies adding and removing nodes with a non-empty list, but empty lists are then a special case. Circular linked lists are most useful for describing naturally circular structures, and have the advantage of being able to traverse the list starting at any point. They also allow quick access to the first and last records through a single pointer (the address of the last element). Typecasting refers to changing an entity of one data type into another. e.g. byte b; (int) b; In object-oriented programming, Inheritance is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, take over (or inherit) attributes and behavior of the pre-existing classes, which are referred to as base classes. It is intended to help reuse existing code with little or no modification. In the next lecture, we will understand the Object Oriented concepts like Class Inheritance and will look at some examples of Type Casting.