Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Python] Need help debugging. Instructions, my code, and sample cases are below! I'm having trouble with ordered_ll.tail. My Code: def add(self, item): #write your code

[Python] Need help debugging. Instructions, my code, and sample cases are below! I'm having trouble with ordered_ll.tail.

image text in transcribed image text in transcribed My Code:

image text in transcribed image text in transcribed image text in transcribed

def add(self, item): #write your code here temp = Node(item) current = self.head previous = None stop = False while current != None and not stop: if current.getValue() > item: stop = True else: previous = current current = current.getNext()

if previous == None: temp.setNext(self.head) self.head = temp else: temp.setNext(current) previous.setNext(temp) self.count+=1

Instructions: In class, we worked on the implementation of a linked list. That data structure keeps the elements of the linked list unsorted. Based on the LinkedList code, implement the data structure OrderedLinkedList with the following characteristics: . OrderedLinkedList) creates a new ordered list that is empty. It needs no parameters and returns nothing. Assume the items in the list are unique . add(item) adds a new Node with value-item to the list making sure that the ascending order . delete(item) removes the Node with value-item from the list. It needs the item and modifies . search(item) searches for the Node with value-item in the list. It needs the item and returns is preserved. It needs the item and returns nothing. [40 pts] the list. You can assume the Node is present in the list. [20 pts] a boolean value. [10 pts] . pop) removes and returns the last Node in the list. It needs nothing and returns an the value of the Node. [20 pts] .isEmpty0 tests to see whether the list is empty. It needs no parameters and returns a boolean value. [5 pts] size) returns the number of items in the list. It needs no parameters and returns an integer [5 pts] * NOTE: There is no partial credit for methods that do not work properly. Code will be tested calling all methods and comparing the final list EXAMPLE >>>ordered 11-OrderedLinkedList () >>> ordered 1 1 add ( 8 ) >>> ordered 11.add (7) >>>ordered 11.add (3) >>>ordered 11.add (-6) >>>ordered 11.add (58) >>>ordered 11.add (33) >>> ordered 11.add (1) >>>ordered 11.add (-88)

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

ISBN: 1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

What will you do or say to Anthony about this issue?

Answered: 1 week ago