0% found this document useful (0 votes)
4 views1 page

Def Isempty (STK)

The document contains a Python implementation of a stack data structure with operations such as push, pop, display, and peek. It includes functions to check if the stack is empty and handles user input for performing stack operations in a loop. The program continues to prompt the user until they choose to exit.

Uploaded by

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

Def Isempty (STK)

The document contains a Python implementation of a stack data structure with operations such as push, pop, display, and peek. It includes functions to check if the stack is empty and handles user input for performing stack operations in a loop. The program continues to prompt the user until they choose to exit.

Uploaded by

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

def isEmpty(stk):

if stk==[]:
return True
else:
return False
def push(stk,pn,pm):
l=[pn,pm]
stk.append(l)
print("added successfully")
def pop(stk):
if isEmpty(stk):
print("stack empty")
else:
print("the popped item is :",stk.pop())
def display(stk):
if isEmpty(stk):
print("stack Empty")
else:
top=len(stk)-1
print("top item is:",stk[top])
for a in range (top-1,-1,-1):
print(stk[a])
def peek(stk):
if isEmpty(stk):
print("stack Empty")
else:
top=len(stk)-1
print("top item is ........:",stk[top])

stk=[]
top=None
while True:
print("stack operations")
print("1.push")
print("2.pop")
print("3.display")
print("4.peek")
print("5.Exit")
ch=int(input("enter your choice(1-5):"))
if ch==1:
pn=input("enter processor name:")
pm=input("enter processor model:")
push(stk,pn,pm)
elif ch==2:
item=pop(stk)
if item=="underflow":
print("stack Empty")
else:
print("deleted item is :",item)
elif ch==3:
display(stk)
elif ch==4:
peek(stk)
elif ch==5:
print("existing")
break
else:
print("invalid choice")

You might also like