Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python Programming assignment: Let's think about doubly-linked lists. Define a class ListNode2, with three attributes: item, left, and rightL. Left link points to the previous

python
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Programming assignment: Let's think about doubly-linked lists. Define a class ListNode2, with three attributes: item, left, and rightL. Left link points to the previous node in the list, right link points to the next node in the list. You can also add the display method to this class (like we did it in class for the ListNode class). Then test your class. For example, create a linked list of 5 values: 34,1, 23, 7, and 10. Display it. Then insert new value, say 8 between 34 and 1 (this time you will have to take care of links pointing to the previous and next node), display the resulting list. Then delete an element, say 7, update the links and display the new list. Use this draft: ListNode2_forStudents.py # ListNode 2.PY class ListNode2: def __init__(self, item - None, leftL - None, rightL - None): "creates a ListNode with the specified data value and two links to the previous node and to the next node postt creates a ListNode with the specified data value and links # put the code here def str (self): for printing the node return str(self.item) def printLR(headNode): **prints all elements following right links, starting with the headNode node - headNode while node is not None: print (node.item, end node - node.rightL print("end of linked list") def printRL(tailNode): w generates a list all elements following left links starting with the tail Node node - tailNode listy -[] while node is not None: listv.append(node.item) node - node.left list - listt 1-1) print("here is the list of elements, following left links", listv) return listv Testing create a linked list of 5 values: 34, 1, 23, 7, and 10. # Displays it. . put the code here, make ni to be 34, and n5 be 10 n5 - ListNode 2 (10) nl - ListNode 2(34,- printing all the nodes, one by one, following right links, then left links # Testing # create a linked list of 5 values: 34, 1, 23, 7, and 10. # Displays it. # put the code here, make nl to be 34, and n5 be 10 n5 - ListNode2(10) nl - ListNode2( 34,...... # printing all the nodes, one by one, following right links, then left links printLR(nl) printRL (n5) # Then insert new value, say 8 between 34 and 1. Display the updated list print("Inserting 8...") put the code here printLR(nl) printRL (n5) the links and display the new list. # Then delete node with val print("Deleting 7...") * put the code here printLR(nl) printRL (n5 ) # ListNode.py class ListNode: definit__(self, item = None, link = None): 'creates a ListNode with the specified data value and link post: creates a ListNode with the specified data value and link''' self.item = item self.link = link

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Generative Artificial Intelligence For Project Management With Aws

Authors: Timothy Krimmel

1st Edition

B0CQV9KWB8, 979-8872627197

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago