Stack Program
Stack Program
def push():
ele=int(input("enter the element to be inserted"))
stack.append(ele)
def pop():
if stack==[]:
print("stack is empty/underflow")
else:
print("the delete element is",stack.pop())
def peek():
top=len(stack)-1
print("the top most element of the stack is",stack[top])
def display():
top=len(stack)-1
print("the stack elements are")
for i in range(top,-1,-1):
print(stack[i])
#main program
stack=[]
opt='y'
while opt=='y' or opt=='Y':
print("stack operation")
print("1.push")
print("2.pop")
print("3.peek")
print("4. display")
opt=int(input("enter your choice"))
if opt==1:
push()
elif opt==2:
pop()
elif opt==3:
peek()
elif opt==4:
display()
else:
print("invalid option")
opt=input("do you want to perform another stack
operation?(y/n)")