In this lab you are asked to complete the python code so that it: • Accepts integers as inputs from a user and appends t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

In this lab you are asked to complete the python code so that it: • Accepts integers as inputs from a user and appends t

Post by answerhappygod »

In This Lab You Are Asked To Complete The Python Code So That It Accepts Integers As Inputs From A User And Appends T 1
In This Lab You Are Asked To Complete The Python Code So That It Accepts Integers As Inputs From A User And Appends T 1 (52.27 KiB) Viewed 27 times
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

# Inserts a new node on the front of list

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

#** Your code goes here **
return self
def chunck_removal(self,nodeA):

#** Your code goes here **
return self

if __name__ == '__main__':

#** Your code goes here **
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 o If the node is not found in the doubly-linked-list, it should display: "Node not found", Display the modified doubly linked list o if the doubly linked list is empty it should print "Empty!" For example, for following input 1 2 3 4. 5 6 -1 6 the output should be: 1 ол во мн 2 3 4 5
1 Input 2 3 -1 7 Your output Your program produced no output Node not found 1 Expected output 2 3
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply