I've attached the question. Below, you will find my python code answer. It doesn't output correctly, as you can see in the image with errors. Code: class Node: def __init__(self, data): self.data = data self.next = None self.prev = None # Empty Doubly Linked List class DoublyLinkedList: def __init__(self): self.head = None def append(self, new_data): if self.head == None: self.head = new_data self.tail = new_data else: self.tail.next = new_data new_data.prev = self.tail self.tail = new_data def printList(self): if(self.head == None): print('Empty!') else: node = self.head while(node is not None): print(node.data), node = node.next def remove(self, current_node): successor_node = current_node.next predecessor_node = current_node.prev if successor_node is not None: successor_node.prev = predecessor_node if predecessor_node is not None: predecessor_node.next = successor_node if current_node is self.head: self.head = successor_node if current_node is self.tail: self.tail = predecessor_node def node_search(self,nodeA): node = self.head while(node is not None): if(node.data==nodeA.data): return True node=node.next return False def chunck_removal(self,nodeA): node = self.head temp=None while(node is not None): if(node.data==nodeA.data): temp.next = None break temp=node node=node.next if __name__ == '__main__': d=DoublyLinkedList() while(True): n=int(input()) if(n==-1): break else: d.append(Node(n)) removeNodeDate=int(input()) if(d.node_search(Node(removeNodeDate))): d.chunck_removal(Node(removeNodeDate)) d.printList() else: print('Node not found')
I've attached the question. Below, you will find my python code answer. It doesn't output correctly, as you can see in the image with errors.
Code:
class Node:
def __init__(self, data):
self.data = data
self.next = None
self.prev = None
# Empty Doubly Linked List
class DoublyLinkedList:
def __init__(self):
self.head = None
def append(self, new_data):
if self.head == None:
self.head = new_data
self.tail = new_data
else:
self.tail.next = new_data
new_data.prev = self.tail
self.tail = new_data
def printList(self):
if(self.head == None):
print('Empty!')
else:
node = self.head
while(node is not None):
print(node.data),
node = node.next
def remove(self, current_node):
successor_node = current_node.next
predecessor_node = current_node.prev
if successor_node is not None:
successor_node.prev = predecessor_node
if predecessor_node is not None:
predecessor_node.next = successor_node
if current_node is self.head:
self.head = successor_node
if current_node is self.tail:
self.tail = predecessor_node
def node_search(self,nodeA):
node = self.head
while(node is not None):
if(node.data==nodeA.data):
return True
node=node.next
return False
def chunck_removal(self,nodeA):
node = self.head
temp=None
while(node is not None):
if(node.data==nodeA.data):
temp.next = None
break
temp=node
node=node.next
if __name__ == '__main__':
d=DoublyLinkedList()
while(True):
n=int(input())
if(n==-1):
break
else:
d.append(Node(n))
removeNodeDate=int(input())
if(d.node_search(Node(removeNodeDate))):
d.chunck_removal(Node(removeNodeDate))
d.printList()
else:
print('Node not found')
![Traceback (most recent call last):
File "main.py", line 72, in <module>
removeNodeDate-int (input ())
EOFError: EOF when reading a line
Input
Your output Your program produced no output
Expected output
Traceback (most recent call last):
File "main.py", line 74, in <module>
d. chunck_removal (Node (removeNodeDate))
File "main.py", line 59, in chunck_removal
temp.next = None
AttributeError: 'NoneType' object has no attribute 'next'
Input
Empty!
1
Your output Your program produced no output
Expected output Empty!
Input
Output differs. See highlights below. Special character legend
Your output
1
Expected output
1
1937
2
-1
7
Node not found
Node not found
14
24](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45d19586-ebc3-4f1a-8702-47e93c6193b1%2F87adfcc7-4188-45b3-9611-8648ea790bda%2Fap96kko_processed.png&w=3840&q=75)
![In this lab you are asked to complete the python code so that it:
• Accepts integers as inputs from a user and appends them to the doubly linked list until the user enters -1
• Next, the user enters an integer and your code should:
o find this in the doubly linked list
o remove that node and all the nodes that comes after it in the list
1
For example, for following input
GAWN
5
o If the node is not found in the doubly-linked-list, it should display: "Node not found",
• Display the modified doubly linked list
6
-1
6
o if the doubly linked list is empty it should print "Empty!"
SIA WNH
the output should be:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45d19586-ebc3-4f1a-8702-47e93c6193b1%2F87adfcc7-4188-45b3-9611-8648ea790bda%2F2bhpfn_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 6 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)