Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python. Define a class ListNode2, with three attributes: item, leftL, and rightL. Left link points to the previous node in the list, right link points

Python. Define a class ListNode2, with three attributes: item, leftL, and rightL. Left link points to the previous node in the list, right link points to the next node in the list. # ListNode2.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 post: creates a ListNode with the specified data value and links''' self.item = item self.leftL = leftL self.rightL = rightL 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 = "\t") node = node.rightL print("end of linked list") def printRL(tailNode): """ generates a list all elements following left links, starting with the tailNode """ node = tailNode listV = [] while node is not None: listV.append(node.item) node = node.leftL listV = listV[::-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 n1 to be 34, and n5 be 10 n5 = ListNode2(10) ... n1 = ListNode2(34) # printing all the nodes, one by one, following right links, then left links printLR(n1) printRL(n5) # Then insert new value, say 8 between 34 and 1. Display the updated list print("Inserting 8...") # put the code here printLR(n1) printRL(n5) # Then delete node with value 7, update the links and display the new list. print("Deleting 7...") # put the code here printLR(n1) printRL(n5) 

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

Step: 3

blur-text-image

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions