Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When I run the code, I keep getting TypeError: NoneType, but I'm not sure how to fix it. I know it has to deal with

When I run the code, I keep getting TypeError: NoneType, but I'm not sure how to fix it. I know it has to deal with the fastRemoveAll and stableRemoveAll. Can you please explain what I am missing?

from gettext import find 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 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: return 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 # children classes class ArrayBufferNoDups(BufferArray): def __init__(self): super().__init__() self.value = None 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 elif find(self.value): return False else: self._intArray[self._numberofelements] = value self._numberofelements += 1 return True 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)) else: return -1 # remove all elements of same value def fastRemoveAll(self, value): value_amount = self.findAll(value) if value_amount != -1: for i in range(value_amount): self.fastRemove(value) else: return False # remove all elements of same value def stableRemoveAll(self, value): value_amount = self.findAll(value) if value_amount != -1: for i in range(value_amount): self.stableRemove(value) else: return False # b_array = BufferArray() # b_array.insert(7) # b_array.insert(8) # b_array.insert(9) # b_array.insert(10) # b_array.insert(11) # b_array.insert(12) # b_array.insert(13) # b_array.insert(14) # b_array.insert(15) # b_array.display() # b_array.stableRemove(8) # b_array.display() # b_array.find(8) # b_array.locationOf(22) # b_array.locationOf(15) # # a_nodups = ArrayBufferNoDups() # a_nodups.insert(11) # a_nodups.insert(12) # a_nodups.insert(13) # a_nodups.insert(14) # a_nodups.insert(15) # a_nodups.insert(16) # a_nodups.insert(17) # a_nodups.insert(18) # a_nodups.insert(19) # a_nodups.insert(20) # a_nodups.insert(21) # a_nodups.insert(22) # a_nodups.insert(23) # a_nodups.insert(24) # a_nodups.insert(25) # a_nodups.insert(26) # a_nodups.insert(27) # a_nodups.insert(28) # a_nodups.insert(29) # a_nodups.insert(30) # a_nodups.insert(14) # a_nodups.display() # a_nodups.stableRemove(14) # a_nodups.display() # a_nodups.find(15) # a_nodups.locationOf(28) a_withdups = ArrayBufferWithDups() array_size = int(input("Enter the size of the array: ")) for i in range(array_size): temp = int(input("enter value of {} element: ".format(i))) a_withdups.insert(temp) # key = int(input("enter value to be removed: ")) a_withdups.display() a_withdups.findAll(11) a_withdups.fastRemoveAll(2) a_withdups.display() # a_withdups.stableRemoveAll(11) a_withdups.display()

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

Students also viewed these Databases questions