NATIONAL PUBLIC SCHOOL, GOPALAPURAM
GRADE XII A&B:
CHAPTER : DATA STRUCTURES
#Implementation of Stack using List
def Push(ele,s):
'''if ele%2==0:
s.append(ele)
top=len(s)-1#-1'''
for k,v in d.items():
if v>75:
s.append(k)
return
def Pop(s):
if s==[]:
return "Stack is empty"
else:
v=s.pop()
if s==[]:
top=None
else:
top=len(s)-1
return v
def display(s):
if s==[]:
print('Stack empty')
else:
#print(s[::-1])
'''a=s[::-1]
for i in a:
if i==top:
print(i,"top")
print(i)'''
top=len(s)-1
print(s[top],"top")
for i in range(top-1,-1,-1):
print(s[i])
def Peek(s):
if s==[]:
print('Stack empty')
else:
top=len(s)-1
print(s[top])
s=[]#stack
top=None
while True:
print("1.Push")
print("2.Pop")
print("3.Peek")
print("4.Display")
print("5.Exit")
c=int(input("Enter your choice:"))
if c==1:
e=int(input("Enter the element to be pushed:"))
Push(e,s)
print('Data added')
elif c==2:
d=Pop(s)
print(d)
elif c==3:
Peek(s)
elif c==4:
display(s)
elif c==5:
break
else:
print(“Invalid Input”)