Question: In the following five problems, you modify the Array class defined in this chapter to make it behave more like Python s list class. For

In the following five problems, you modify the Array class
defined in this chapter to make it behave more like
Pythons list class. For each solution, include code that tests your
modifications to the Array class. I have given starter file for each
problem as a hint.
1. Add an instance variable logicalSize to the Array class. This
variable is initially 0 and will track the number of items currently
available to users of the array.
Then add the method size() to the Array class. This method
should return the arrays logical size. The method __len__ should
still return the arrays capacity or physical size.
2. Add the methods grow and shrink to the Array class. These
methods should use the strategies discussed in this chapter to
increase or decrease the length of the list contained in the array.
Make sure that the physical size of the array does not shrink
below the user-specified capacity and that the arrays cells use the
fill value when the arrays size is increased.
3. Add the methods insert and pop to the Array class. These
methods should use the strategies discussed in this chapter,
including adjusting the length of the array, if necessary.
The insert method expects a position and an item as arguments
and inserts the item at the given position. If the position is greater
than or equal to the arrays logical size, the method inserts the
item after the last item currently available in the array.
The pop method expects a position as an argument and removes
and returns the item at that position. The pop methods
precondition is 0= index size(). The remove method should
also reset the vacated array cell to the fill value.
4. Add the method __eq__ to the Array class. Python runs this
method when an Array object appears as the left operand of
 In the following five problems, you modify the Array class defined

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!