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

Stack Code

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

Stack Code

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

#PROGRAM TO IMPLEMENT STACK OPERATIONS USING LIST

def Push(S,E):
S.append(E)
print("Element inserted...")
print(S)

def isEmpty(S):
if S==[]:
return True
else:
return False

def Pop(S):
if isEmpty(S):
print("Stack is Empty...Underflow Case...")
else:
print("Deleted element is ",S.pop())

def Peek(S):
if isEmpty(S):
print("Stack is Empty...")
else:
print("Element at top of the Stack:", S[-1])

def Display(S):
for i in range(len(S)-1,-1,-1):
print(S[i])

Stack=[]
while True:
print("******STACK OPERATIONS******")
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 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