Question: from dynamic _ array import * class StackException ( Exception ) : Custom exception to be used by Stack class DO NOT
from dynamicarray import
class StackExceptionException:
Custom exception to be used by Stack class
DO NOT CHANGE THIS METHOD IN ANY WAY
pass
class Stack:
def initself:
Init new stack based on Dynamic Array
DO NOT CHANGE THIS METHOD IN ANY WAY
self.da DynamicArray
def strself str:
Return content of stack in humanreadable form
DO NOT CHANGE THIS METHOD IN ANY WAY
out "STACK: strselfdalength elements.
out joinstrselfdai for i in rangeselfdalength
return out
def isemptyself bool:
Return True is the stack is empty, False otherwise
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.daisempty
def sizeself int:
Return number of elements currently in the stack
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.dalength
#
def pushself value: object None:
TODO: Write this implementation
pass
def popself object:
TODO: Write this implementation
pass
def topself object:
TODO: Write this implementation
pass
# BASIC TESTING
if namemain:
print
# push example
s Stack
prints
for value in :
spushvalue
prints
print
# pop example
s Stack
try:
printspop
except Exception as e:
printException: typee
for value in :
spushvalue
for i in range:
try:
printspop
except Exception as e:
printException: typee
print
# top example
s Stack
try:
stop
except Exception as e:
printNo elements in stack", typee
spush
spush
prints
printstop
printstop
prints
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
