stack = []
max_val = int(input("Enter the maximum number or elements:"))
while True:
print("STACK OPERATIONS...")
print("1.Push")
print("2.Pop")
print("3.Peek")
print("4.Display Stack")
print("5.Exit")
choice = int(input("Enter your choice:"))
if choice == 1:
if len(stack) == max_val:
print("Stack Overflow!")
else:
val = int(input("Enter the element to be pushed:"))
stack.append(val)
elif choice == 2:
if len(stack) == 0:
print("Stack Underflow!")
else:
val = stack.pop()
print(val, "popped out of the Stack...")
elif choice == 3:
val = stack[-1]
print("Peek is", val)
elif choice == 4:
print("Displaying all Stack elements...")
print(stack)
elif choice == 5:
break
else:
print("Invalid choice!")