[go: up one dir, main page]

0% found this document useful (0 votes)
18 views2 pages

Stack Operations Menu Program

The document outlines a menu-driven program for stack operations including push, pop, peek, and display functionalities. It defines functions to handle these operations and checks for stack underflow and emptiness. The program runs in a loop, allowing users to perform stack operations until they choose to exit.

Uploaded by

vijay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Stack Operations Menu Program

The document outlines a menu-driven program for stack operations including push, pop, peek, and display functionalities. It defines functions to handle these operations and checks for stack underflow and emptiness. The program runs in a loop, allowing users to perform stack operations until they choose to exit.

Uploaded by

vijay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
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