Professional Documents
Culture Documents
stk=[]
top=None
top=len(stk)
stk.append(val)
def peek(stk):
top=len(stk)-1
if top<0:
print("stack is empty")
else:
print(stk[top])
def Pop(stk):
top=len(stk)-1
if top<0:
print("stack is empty")
else:
stk.pop()
def display(stk):
top=len(stk)-1
if top<0:
print("stack is empty")
else:
for i in range(top,-1,-1):
print(stk[i])
ch=0
while(ch!=5):
print("\n1. push")
print("\n2. peek")
print("\n3. pop")
print("\n4. display")
print("\n5. Exit")
if ch==1:
push(stk,v)
elif ch==2:
peek(stk)
elif ch==3:
Pop(stk)
elif ch==4:
display(stk)
QUEUES:
que=[]
front=None
rear=None
def enq(que, val):
if len(que)==0:
front=rear=0
else:
rear=len(que)
que.append(val)
def deq(que):
if len(que)==0:
print("queue is empty")
else:
print("the Name to be removed is=", que[0])
front=0
rear=len(que)-1
if(front==rear):
que.pop(0)
front=rear=None
else:
que.pop(0)
rear=rear-1
def display(que):
if len(que)==0:
print("queue is empty")
else:
for i in range(0,len(que)):
print(que[i])
ch=0
while(ch!=4):
print("\n1. add name")
print("\n2. delete name")
print("\n3. display")
print("\n4. Exit")
ch=int(input("\n your ch(1-4)"))
if ch==1:
v=str(input("\n enter Name to be added:"))
enq(que,v)
elif ch==2:
deq(que)
elif ch==3:
display(que)
RECURSION: