Stack Implementation using List
Stack Implementation using List
#"""
#Stack : implemented as a list
#top : integer having position of topmost element in Stack
#"""
while True :
print ("STACK OPERATIONS")
print ("1. Peek")
print ("2. Push")
print ("3. Pop")
print ("4. Display Stack")
print ("5. Exit")
if ch == 1 :
item = Peek (Stack)
if item == "Underflow" :
print ("Underflow! Stack is empty!")
else :
print ("Topmost item is ", item)
elif ch == 2 :
item = int (input ("Enter item : "))
Push (Stack, item)
elif ch == 3 :
item = Pop (Stack)
if item == "Underflow" :
print ("Underflow! Stack is empty!")
else :
print ("Popped item is ", item)
elif ch == 4 :
Display (Stack)
elif ch == 5 :
break
else :
print ("Invalid choice!")