Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will implement various methods of the Dynamic array and the Bag ADT with the provided skeleton source code files below. For detailed instructions and
You will implement various methods of the Dynamic array and the Bag ADT with the provided skeleton source code files below. For detailed
instructions and method descriptions, please read this document very carefully: OSU CS A Wpdf darr
Use the provided tests in the skeleton code to test your code. You are encouraged to write additional unit tests, however, you are not
permitted to share any additional tests with other students.
Skeleton Code Files:
dynamic arraypyrequires staticarray.py from Assignment
bag
dapy darr
Scoring
Dynamic Array points:
resize points
append points
insertatindex points
removeatindex points
slice points
merge points
map points
filter points
reduce points
findmode points
Bag points:
add points
remove points
count points
clear points
equal points
nextiterator implementation points
What to Turn In files
The following Python files should be submitted through Gradescope from this assignment:
dynamicarray.py
bagdapy
Part
from staticarray import StaticArray
class DynamicArrayExceptionException:
Custom exception class to be used by Dynamic Array
DO NOT CHANGE THIS CLASS IN ANY WAY
pass
class DynamicArray:
def initself startarrayNone:
Initialize new dynamic array
DO NOT CHANGE THIS METHOD IN ANY WAY
self.size
self.capacity
self.data StaticArrayselfcapacity
# populate dynamic array with initial values if provided
# before using this feature, implement append method
if startarray is not None:
for value in startarray:
self.appendvalue
def strself str:
Return content of dynamic array in humanreadable form
DO NOT CHANGE THIS METHOD IN ANY WAY
out DYNARR SizeCap:
out strselfsize strselfcapacity
out joinstrselfdata for in rangeselfsize
return out
def iterself:
Create iterator for loop
DO NOT CHANGE THIS METHOD IN ANY WAY
self.index
return self
def nextself:
Obtain next value and advance iterator
DO NOT CHANGE THIS METHOD IN ANY WAY
try:
value selfselfindex
except DynamicArrayException:
raise StopIteration
self.index
return value
def getatindexself index: int object:
Return value from given index position
Invalid index raises DynamicArrayException
DO NOT CHANGE THIS METHOD IN ANY WAY
if index or index self.size:
raise DynamicArrayException
return self.dataindex
def setatindexself index: int, value: object None:
Store value at given index in the array
Invalid index raises DynamicArrayException
DO NOT CHANGE THIS METHOD IN ANY WAY
if index or index self.size:
raise DynamicArrayException
self.dataindex value
def getitemself index object:
Same functionality as getatindex method above,
but called using arrayindex syntax
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.getatindexindex
def setitemself index, value None:
Same functionality as setatindex method above,
but called using arrayindex syntax
DO NOT CHANGE THIS METHOD IN ANY WAY
self.setatindexindex value
def isemptyself bool:
Return True is array is empty False otherwise
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.size
def lengthself int:
Return number of elements stored in array
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.size
def getcapacityself int:
Return the capacity of the array
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.capacity
def printdavariablesself None:
Print information contained in the dynamic array.
Used for testing purposes.
DO NOT CHANGE THIS METHOD IN ANY WAY
printfLength: selfsize Capacity: selfcapacityselfdata
#
def resizeself newcapacity: int None:
TODO: Write this implementation
pass
def appendself value: object None:
TODO: Write this implementation
pass
def insertatindexself index: int, value: object None:
TODO: Write this implementation
pass
def removeatindexself index: int None:
TODO: Write this implementation
pass
def sliceself startindex: int, size: int "DynamicArray":
TODO: Write this implementation
pass
def mergeself secondda: "DynamicArray" None:
TODO: Write this implementation
pass
def m
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