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')

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Transcribed Image Text: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
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:
Transcribed Image Text: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:
Expert Solution
steps

Step by step

Solved in 6 steps with 4 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education