Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

entire implementation of the DoublyLinkedList class

Sumit Rawal answered on May 23, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • linked list with classes c++
  • how to implement linked list in java without using collection framework
  • LINKEDLIST JAVA
  • LinkedList java
  • linked list java
  • Implementing the LinkedList Class in java list
  • implementing linked list in java
  • values for classList
  • Java LinkedList
  • implementation linked list
  • Java Access LinkedList elements
  • simple link list java
  • linked list java implementation
  • linked list in java
  • Linked list implementation in Java source code

  • entire implementation of the DoublyLinkedList class

    0

    class Node:

    def __init__(self, data):

    self.data = data

    self.next = None

    self.prev = None

    class DoublyLinkedList:

    def __init__(self):

    self.head = None

    def append(self, data):

    if self.head is None:

    new_node = Node(data)

    self.head = new_node

    else:

    new_node = Node(data)

    cur = self.head

    while cur.next:

    cur = cur.next

    cur.next = new_node

    new_node.prev = cur

    def prepend(self, data):

    if self.head is None:

    new_node = Node(data)

    self.head = new_node

    else:

    new_node = Node(data)

    self.head.prev = new_node

    new_node.next = self.head

    self.head = new_node

    def print_list(self):

    cur = self.head

    while cur:

    print(cur.data)

    cur = cur.next

    dllist = DoublyLinkedList()

    dllist.prepend(0)

    dllist.append(1)

    dllist.append(2)

    dllist.append(3)

    dllist.append(4)

    dllist.prepend(5)

    dllist.print_list() 

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.