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

Stack Program

Uploaded by

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

Stack Program

Uploaded by

kumarrohith3168
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

24] Write a python program to perform the operations on stack.

def push():
ele=int(input("enter the element to be inserted"))
stack.append(ele)

def pop():
if stack==[]:
print("stack is empty/underflow")
else:
print("the delete element is",stack.pop())

def peek():
top=len(stack)-1
print("the top most element of the stack is",stack[top])

def display():
top=len(stack)-1
print("the stack elements are")
for i in range(top,-1,-1):
print(stack[i])

#main program
stack=[]
opt='y'
while opt=='y' or opt=='Y':
print("stack operation")
print("1.push")
print("2.pop")
print("3.peek")
print("4. display")
opt=int(input("enter your choice"))
if opt==1:
push()
elif opt==2:
pop()
elif opt==3:
peek()
elif opt==4:
display()
else:
print("invalid option")
opt=input("do you want to perform another stack
operation?(y/n)")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy