Program 1
# Static implementation of Stack
import os
MAXSIZE=10
top=-1
mystack=[]
def push():
global MAXSIZE
global top
if(top==MAXSIZE-1):
print("Stack is overflow")
else:
n=int(input("Enter an element for push: "))
top=top+1
mystack.insert(top,n)
def pop():
global MAXSIZE
global top
if(len(mystack)==0):
print("Stack is empty ")
else:
print("Poped element is: ",mystack[top])
del mystack[top]
top=top-1
def display():
if(len(mystack)==0):
print("Stack is empty ")
else:
print("Elements of stack ")
for element in reversed(mystack) :
print(element)
# Main
os.system('cls')
while(1):
print("------------------Stack Menu--------------------")
print("1. Push \n 2. Pop \n 3. Display \n 4.Exit")
print("---------------------------------------------------")
choice=int(input("Enter your choice: "))
if(choice==1):
push()
elif(choice==2):
pop()
elif(choice==3):
display()
else:
break