Untitled

mail@pastecode.io avatar
unknown
python
a year ago
567 B
1
Indexable
Never
stk=[]
def push(stk,n):
stk.append(n)
top=len(stk)-1
def pop(stk):
if len(stk)==0:
print("underflow")
else:
e=stk.pop)
print("element popped is :",e)
top=len(stk)-1
def display(stk):
if len(stk)==0:
print("underflow")
else:
print(stk|len(stk)-1],;"<--top")
for i in range(len(stk)-2,-1,-1):
print(stk[i])
while True:
print("1:Push")
print("2:Pop")
print("3:Display")
print("4:Exit")
ch=int(input("enter your choice:")
if ch==1:
n=int(input("Enter the number:"))
push(stk,n)
elif ch==2:
pop(stk)
elif ch==3:
display(stk)
elif ch==4:
break
else:
print("Invalid choice")