Stack Implementation

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#Stack Implementation

stack=list()
size=int(input('enter the size of stack'))

#creating fn for push


def do_push():
if len(stack)==size:
print('overflow')
else:
ele=input('enter any vowel')
stack.append(ele)
print('vowel has been pushed')

#creating fn for pop


def do_pop():
if len(stack)==0:
print('underflow')
else:
ele=input('enter any vowel')
stack.pop(ele)

#creating fn for accesing element


def do_traversal():
if len(stack)!=0:
for i in stack:
print(i)
else:
print("no element")

while True:
print('press 0 for push \npress 1 for pop \npress 2 for traversal')
ch=int(input('enter your choice'))
if ch==0:
do_push()
elif ch==1:
do_pop()
elif ch==2:
do_traversal()
else:
print('invalid choice')

You might also like