DEV Community

Durga Pokharel
Durga Pokharel

Posted on

Day 49 Of 100DaysOfCode: Advanced Linked List

Today is my 49th day of #100DaysOfCode and #python. Today I studied more about data structure. Advanced liked list. It is similar to the single linked list. Unlike in single linked list we can not traverse in forward and backward direction but in doubly linked list we can.

Doubly linked list contains a link element called first and last. Each link carries a data fields and two linked fields called next and prev.

Python code

We create a node class with three member variable item, data next and previous. Data variable will store the actual data for the node. The next store the reference to the next node and prev stores the reference to the privious node.

class Node:
   def __init__(self, data): = data = None
      self.prev = None

class doubly_linked_list:

   def __init__(self):
      self.head = None

   def push(self, NewVal):
      NewNode = Node(NewVal) = self.head
      if self.head is not None:
         self.head.prev = NewNode
      self.head = NewNode

   def listprint(self, node):
      while (node is not None):
         last = node
         node =

dllist = doubly_linked_list()
Enter fullscreen mode Exit fullscreen mode

We need to create the doubly linked list class, which contains different doubly linked list related functions.
Output of the above function is,

Enter fullscreen mode Exit fullscreen mode

Day 49 Of #100DaysOfCode and #Python
Advanced Linked List Data Structure In Python#CodeNewbie #womenintech #DEVCommunity #beginner #100DaysOfCode #WomenWhoCode #Python

— Durga Pokharel (@mathdurga) February 11, 2021

Top comments (1)

otumianempire profile image
Michael Otu

I was looking at this code, from yesterday,

On day 48, the Node objects were created outside and passed to the SLinkedList but here, you pass the data and a new Node is created when you call push..

So far so good.. thumbs up..