Python program to create and display a doubly linked list

Python program to create and display a doubly linked list

In this program, you’ll be learning how to create and display a doubly linked list.

Doubly Linked List is a variation of the linked list. it’s a data structure that consists of a set of the sequential linked list which is tearmd as the node. (Two ends of the link list can also be called as a node).

And each node contains the 3 fields which are, two Link fields (as each node jas two ends) and one data field.

The first node of a list is called as head if a link list and end is called as the tail of the link list.

Program to create and display a doubly linked list.

class Node:    
    def __init__(self,data):    = data;    
        self.previous = None;    = None;    
class DoublyLinkedList:    
    def __init__(self):    
        self.head = None;    
        self.tail = None;    
    def addNode(self, data):    
        newNode = Node(data);    
        if(self.head == None):    
            self.head = self.tail = newNode;    
            self.head.previous = None;    
   = None;    
   = newNode;    
            newNode.previous = self.tail;    
            self.tail = newNode;    
   = None;    
    def display(self):    
        current = self.head;    
        if(self.head == None):    
            print("List is empty");    
        print("Nodes of doubly linked list: ");    
        while(current != None):     
            current =;    
dList = DoublyLinkedList();    


Nodes of doubly linked list: 
1 2 3 4 5

Related Program

  1. Python Program to Find LCM
  2. Python Program to Find HCF or GCD
  3. Python Program To Display Powers of 2 Using Anonymous Function
  4. Python Program to Display Calendar
  5. Python Program to find the Square Roots
  6. Python Program to Shuffle Deck of Cards
  7. Python program convert decimal number to binary number using recursion
  8. Python Program to Find Factorial of a Number Using Recursion
  9. Python Program to Check if a Number is Positive, Negative or 0
  10. Python Program to Generate a Random Alphanumeric String

Ask your questions and clarify your/others doubts on how you can create and display double linked list by commenting. Python Documentation