0% found this document useful (0 votes)
10 views

Stack Implementation

Stack implementation in python

Uploaded by

vijay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Stack Implementation

Stack implementation in python

Uploaded by

vijay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#Menu Driven Program using Stack

#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

You might also like