Answered step by step
Verified Expert Solution
Question
1 Approved Answer
resize ( self , new _ capacity: int ) - > None: This method changes the underlying storage capacity for the elements in the dynamic
resizeself newcapacity: 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 removeatindex or insertatindex to manage the
capacity of the underlying data structure.
The method should only accept positive integers for newcapacity. Additionally,
newcapacity cannot be smaller than the number of elements currently stored in the
dynamic array which is tracked by the self.size variable If newcapacity is not a
positive integer, or if newcapacity is less than self.size, this method should not do any
work and immediately exit.
Example #:
da DynamicArray
daprintdavariables
daresize
daprintdavariables
daresize
daprintdavariables
daresize
daprintdavariables
Output:
Length: Capacity: STATARR Size: None None, None, None
Length: Capacity: STATARR Size: None None, None, None, None, None,
None, None
Length: Capacity: STATARR Size: None None
Length: Capacity: STATARR Size: None None
NOTE: Example below will not work properly unless the append method is implemented.
Example #:
da DynamicArray
printda
daresize
printda
daresize
printda
Output:
DYNARR SizeCap:
DYNARR SizeCap:
DYNARR SizeCap:
Please code in Python
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started