Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

2. Develop a persuasive topic and thesis

Answered: 1 week ago

Question

1. Define the goals of persuasive speaking

Answered: 1 week ago