Stack Implementation
Stack Implementation
#Stack Operations
def isEmpty(stk):
if stk==[]:
return True
else:
return False
def push(stk,ele):
stk.append(ele)
print("Element Inserted")
print(stk)
def pop(stk):
if isEmpty(stk):
print("Stack is Empty... Under Flow Case...")
else:
print("Element Deleted is :",stk.pop())
def peek(stk):
if isEmpty(stk):
print("Stack is Empty...")
else:
print("Element at Top of the Stack:",stk[-1])
def display(stk):
if isEmpty(stk):
print("Stack is Empty...")
else:
for i in range(len(stk)-1,-1,-1):
print(stk[i])
stack=[]
while True:
print(".....Stack Operation....")
print("1.Push")
print("2.Pop")
print("3.Peek")
print("4.Display")
print("5.Exit")
ch=int(input("Enter your Choice:"))
if ch==1:
element=int(input("Enter the element which you want to push:"))
push(stack,element)
elif ch==2:
pop(stack)
elif ch==3:
peek(stack)
elif ch==4:
display(stack)
elif ch==5:
break