3. What will be the output of the following code after deleting value 20?
class Node:
def __init__(self, data):
self.data = data
self.prev = None
self.next = None
class DoublyLinkedList:
def __init__(self):
self.head = None
def append(self, data):
new_node = Node(data)
if not self.head:
self.head = new_node
return
last = self.head
while last.next:
last = last.next
last.next = new_node
new_node.prev = last
def delete_by_value(self, value):
current = self.head
while current:
if current.data == value:
if current.prev:
current.prev.next = current.next
else:
self.head = current.next
if current.next:
current.next.prev = current.prev
break
current = current.next
def print_list(self):
current = self.head
result = []
while current:
result.append(current.data)
current = current.next
print(result)
dll = DoublyLinkedList()
dll.append(10)
dll.append(20)
dll.append(30)
dll.delete_by_value(20)
dll.print_list()