Question: The remove ( ) method resizes the array when necessary by removing an item from the array if it exist Be sure to reuse your

The remove() method resizes the array when necessary by removing an item from the array if it exist
Be sure to reuse your solution from Programming Exercise 5.3 as your starter file for the arraybag.py file.
In the arraybag.py file define the remove() method in the ArrayBag class by completing the following:
Check the precondition and raise a KeyError if necessary
Precondition: item is in self.
Raises: KeyError if item in not in self.
Postcondition: item is removed from self.
Search for the index of the target item
Shift items to the left of target up by one position
Decrement logical size
Check array memory here and decrease it if necessary
To test your program run the testResize() method in the testbag.py file.
Added 100 items, length of bag =100
Expect 160 as length of array =160
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99}
Removed 76 items, expect 24 as length of bag: 24
Expect 80 as length of array =80
Removed remaining items, length of bag =0
Expect 10 as length of array =10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!