Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble with the fastRemoveAll and stableRemoveAll functions. How can I fix both functions to remove all elements of the same value in

I am having trouble with the fastRemoveAll and stableRemoveAll functions. How can I fix both functions to remove all elements of the same value in class ArrayBufferWithDups? class BufferArray: def __init__(self): self._numberofelements = 0 self._buffer_size = 20 # None is used to define a null data type or no value at all. self._intArray = [None] * self._buffer_size def insert(self, value): if self._numberofelements == self._buffer_size - 1: return False else: self._intArray[self._numberofelements] = value self._numberofelements += 1 return True # def display(self): print(",".join(map(str, self._intArray[:self._numberofelements]))) # def locationOf(self, value): if value in self._intArray: print(self._intArray.index(value)) else: print(-1) # def find(self, value): if value in self._intArray: print(True) else: print(False) # def fastRemove(self, value): if value in self._intArray.index(value): index = self._intArray.index(value) self._intArray[index], self._intArray[self._numberofelements - 1] = self._intArray[ self._numberofelements - 1], \ self._intArray[index] self._numberofelements -= 1 return True else: return False # def stableRemove(self, value): if value in self._intArray: index = self._intArray.index(value) self._intArray = self._intArray[:index] + self._intArray[index + 1:] self._numberofelements -= 1 return True else: return False
class ArrayBufferWithDups(BufferArray): def __init__(self): super().__init__() self._numberofelements = 0 self._buffer_size = 20 # None is used to define a null data type or no value at all. self._intArray = [None] * self._buffer_size def findAll(self, value): if value in self._intArray: print(self._intArray.count(value) + 1) else: return -1 # remove all elements of the same value def fastRemoveAll(self, value): for value in self._intArray: try: self._intArray.remove(value) except ValueError: pass # remove all elements of the same value def stableRemoveAll(self, value): # if value in self._intArray: index = self._intArray.index(value) while value in self._intArray[index]: self._intArray.remove(value)

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions