Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
Best answer

Program of Doubly linked list 

program : 

class node:

    def __init__(self, next=None, prev=None, value=None): = next # reference to next node 

        self.prev = prev # reference to previous node

        self.value = value

class DoublyLinkedList:

    def __init__(self):


    def insert_at_first(self, value): 

    # Node & assign the value 

        newnode = node(value = value) 

    # Make next of newnode as start and prevs as NULL  = self.start 

        newnode.prev = None

    # change prev of start node to newnode  

        if self.start!=None: 

            self.start.prev = newnode  

    # move the start to point to the newnode 

            self.start = newnode  

    def insert_after(self, prev, value):

        if prev==None: # check if the given prev_node is NULL

            print("This node doesn't exist ") 


        #allocate node  & assign value 

        newnode = node(value =value) 

        # Make next of new node as next of prevnode  =

        # Make the next of prevnode as newnode   = newnode 

        # Make prevnode as previous of newnode 

        newnode.prev = prev  

        # Change previous of new_node's next node  

        if is not None: 

   = newnode

    def insert_at_end(self, value): 

        # create node and assign value 

        newnode = node(value = value) 

        last = self.start 

# new node is going to be the last node, so make next of it as NULL  = None

# If the Linked List is empty, then make the new node as head 

        if self.start is None: 

            newnode.prev = None

            self.start = newnode 


        # Else traverse till the last node  

        while ( is not None): 

            last =

        # Change the next of last node   = newnode 

        # Make last node as previous of new node 

        newnode.prev = last 

    def delete_node(self, node_to_del):

        if self.start is None or node_to_del is None:


        # If node to be deleted is head node 

        if self.start == node_to_del: 

            self.start =

        # Change next only if node to be deleted is NOT 

        # the last node 

        if is not None: 

   = node_to_del.prev    

# Change prev only if node to be deleted is NOT first node 

        if node_to_del.prev is not None: 


    def display(self, node): 

        print("linked list ")

        while(node is not None): 


            last = node 

            node =

        print("\n reverse linked list ")

        while(last is not None): 


            last = last.prev 

llist = DoublyLinkedList()  








llist.insert_after(, 8)




Output : 

linked list





reverse linked list 



For more Rajasthan Technical University CSE-III Sem DSA Lab Experiments  CLICK HERE


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs


About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © Social::   |  | 


Free Online Directory