You are on page 1of 2

# -*- coding: utf-8 -*-

"""
Created on Fri Mar 18 13:11:13 2022

@author: Pratyush
"""

def isempty (stk):


if len(stk)==0:
return True
else:
return False
def Push (stk, data):
stk.append(data)
def Pop (stk):
if isempty (stk):
print ("Underflow")
return None
else:
return stk.pop()
def Display (stk):
print ("Elements of stk are:")
for d in range (len(stk)-1,-1,-1):
print(stk [d])
def top (stk):
if isempty (stk):
print ( )
return None
else:
return stk[len(stk)-1]
def peek (stk):
if isempty (stk):
return None
else:
return stk[len(stk)-1]

def size (stk):


return len(stk)
nu = []
Push (nu,5)
Push (nu,12)
Push (nu,3)
Display (nu)
Pop (nu)
print (size (nu))
print (top(nu))
print (size(nu))
Push (nu, 30)
Display (nu)
m = Pop(nu)-20
n=Pop(nu)-10
print(m)
print (n)
print(m+n)
print (nu)
Display (nu)

1
2

You might also like