Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Needs help Python 3.6 Data Structure! from node import Node class OrderedList: def __init__(self): self.head = None def isEmpty(self): return self.head == None def length(self):

Needs help Python 3.6 Data Structure!
image text in transcribed
from node import Node
class OrderedList:
def __init__(self):
self.head = None
def isEmpty(self):
return self.head == None
def length(self):
current = self.head
count = 0
while current != None:
count += 1
current = current.getNext()
return count
def __str__(self):
msg = ""
current = self.head
while current != None:
msg += str(current.getData()) + " "
current = current.getNext()
return msg
def remove(self, item):
current = self.head
previous = None
found = False
while not found:
if current.getData() == item:
found = True
else:
previous = current
current = current.getNext()
if previous == None:
self.head = current.getNext()
else:
previous.setNext(current.getNext())
def search(self, item):
current = self.head
found = False
stop = False
while current != None and not found and not stop:
if current.getData() == item:
found = True
else:
if current.getData() > item:
stop = True
else:
current = current.getNext()
return found
def add(self, item):
current = self.head
previous = None
stop = False
while current != None and not stop:
if current.getData() > item:
stop = True
else:
previous = current
current = current.getNext()
temp = Node(item)
if previous == None:
temp.setNext(self.head)
self.head = temp
else:
temp.setNext(current)
previous.setNext(temp)
image text in transcribed
Design an algorithm for the following methods for the OrderedList class: indexlitem)- returns the position of item in the list. It needs the item and returns the index. Assume the list has at least one item pop(pos)-removes and returns the item at position pos. It needs the position and returns the item. Assume the item is in the list

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago