Doubly Linked List

By | October 6, 2021
Doubly Linked List

Doubly Linked List is an extension of Linked List in which we have two pointer variables, so we could traverse back and forth directions. It contains two pointers conventionally named, next and prev, in next we store the address or object of next element or node and in prev, we store the address of the previous object.

Like a simple linked-list Doubly linked list also store its element sequentially so if we want to visit the last element, first we would have to traverse through all other nodes.


Some Important terminology of Doubly Linked List:

Node: A node is a collection of data value and two pointers next and prev

Next: Next is a pointer which will hold the address or object of sequential next node.

Prev: Prev is a pointer which holds the address or object of the previous node.

Doubly Linked List (DLL) Representation

  • The first node of Doubly linked list is a head node and its prev pointer will hold Null Value
  • Each node of the doubly Linked list will contain a data value and two pointers
  • The next pointer will hold the address of the next node.
  • The last node’s prev variable will contain a Null value.

DLL Basic Operations

Here are some operations which we can apply on a Doubly linked list:

  • Insertion
  • Deletion
  • Insert Last
  • Delete last
  • Insert After
  • Delete
  • Forward Traversing
  • Backward Traversing

Advantages and Disadvantages of DLL


  • With the Doubly Linked list, we can transverse back and forth directions.
  • The Insertion and deletion operations on the doubly linked list are easier. Unlike simple linked list here we do not need to traverse to the predecessor node and store its reference. Rather, in a doubly-linked list, the reference of the predecessor node can be retrieved from the node that we want to delete.


  • Each node requires two variables which require more memory.
  • We have to manage both the pointers to make an effective doubly-linked list data structure.

Doubly-Linked-List Implementation


class Node:
    def __init__(self, next=None, prev=None, data=None): = next
        self.prev = prev = data
class DoublyLinkedList:
    def __init__(self):
        self.head = None 
    def Inset_at_Beginning(self, data):
        new_node = Node(data = data) = self.head
        new_node.prev = None 
        if self.head is not None:
            self.head.prev = new_node
        self.head = new_node 
    def Insert_at_Middle(self, prev, data):  
        if prev is None:
            print("No such node")
        new_node = Node(data = data)  = = new_node
        new_node.prev = prev
        if is not None:
   = new_node
    def Insert_at_End(self, data):
        new_node = Node(data = data)
        last = self.head = None
        if self.head is None:
            new_node.prev = None
            self.head = new_node
        while ( is not None):
            last = = new_node
        new_node.prev = last
    def delete_list_element (self, data):
        if self.head is None:
            print("list has no element to delete")
        if is None:
            if self.head.item == data:
                self.head = None
                print("Item not found")
        if == data:
            self.head =
            self.head.prev = None
        n = self.head
        while is not None:
            if ==data:
            n =
        if is not None:
   = n.prev
            if == data:
       = None
                print("Element not found")
    def Traverse_complete_llist(self):
        if self.head is None:
            print("List has no element")
            n = self.head
            while n is not None:
                print( , " ")
                n =

People are also reading:

Leave a Reply

Your email address will not be published. Required fields are marked *