Question: resize ( self , new _ capacity: int ) - > None: This method changes the underlying storage capacity for the elements in the dynamic

resize(self, new_capacity: int)-> None:
This method changes the underlying storage capacity for the elements in the dynamic array.
It does not change the values or the order of any elements currently stored in the array.
It is intended to be an internal method of the DynamicArray class, called by other class
methods such as append(), remove_at_index(), or insert_at_index(), to manage the
capacity of the underlying data structure.
The method should only accept positive integers for new_capacity. Additionally,
new_capacity cannot be smaller than the number of elements currently stored in the
dynamic array (which is tracked by the self._size variable). If new_capacity is not a
positive integer, or if new_capacity is less than self._size, this method should not do any
work and immediately exit.
Example #1:
da = DynamicArray()
da.print_da_variables()
da.resize(8)
da.print_da_variables()
da.resize(2)
da.print_da_variables()
da.resize(0)
da.print_da_variables()
Output:
Length: 0, Capacity: 4, STAT_ARR Size: 4[None, None, None, None]
Length: 0, Capacity: 8, STAT_ARR Size: 8[None, None, None, None, None, None,
None, None]
Length: 0, Capacity: 2, STAT_ARR Size: 2[None, None]
Length: 0, Capacity: 2, STAT_ARR Size: 2[None, None]
NOTE: Example 2 below will not work properly unless the append() method is implemented.
Example #2:
da = DynamicArray([1,2,3,4,5,6,7,8])
print(da)
da.resize(20)
print(da)
da.resize(4)
print(da)
Output:
DYN_ARR Size/Cap: 8/8[1,2,3,4,5,6,7,8]
DYN_ARR Size/Cap: 8/20[1,2,3,4,5,6,7,8]
DYN_ARR Size/Cap: 8/20[1,2,3,4,5,6,7,8]could you fix this code, because You are NOT allowed to use ANY built-in Python data structures and/or their
methods in any of your solutions. This includes built-in Python lists,
dictionaries, or anything else. You must solve this portion of the assignment
by importing and using objects of the StaticArray class (prewritten for you),
and using class methods to write your solution.

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!