You are on page 1of 3

Stack and Queue-Exam Based Questions

Write a function AddCustomer(Customer) in Write a function DeleteCustomer() to delete a


Python to add a new Customer information Customer information from a list of CStack. The
NAME into the List of CStack and display the function delete the name of customer from the
information. stack.
CStack=[] CStack=[]
def AddCustomer(Customer): def DeleteCustomer():
CStack.append(Customer) if (CStack ==[]):
if len(CStack)==0: print(“There is no Customer!”)
print (“Empty Stack”) else:
else: print(“Record deleted:”,CStack.pop())
print (CStack)

Write A Function Python, MakePush(Package) Write InsQueue(Passenger) and


and MakePop (Package) to add a new Package DelQueue(Passenger) methods/function in
and delete a Package form a List Package Python to add a new Passenger and delete a
Description, considering them to act as push and Passenger from a list ‘names’ , considering them
pop operations of the Stack data structure. to act as insert and delete operations of the
def MakePush(Package): Queue data structure.
a=int(input("enter package title:")) def InsQueue (Passenger):
Package.append(a) a=int(input("enter passenger name:"))
Passenger.append(a)
def MakePop(Package):
if(Package==[]): def DelQueue (Passenger):
print("Stack empty") if(Passenger ==[]):
else: print("queue empty")
print("Deleted element:",Package.pop()) else:
print(Passenger.pop(0))

Write AddCustomer(Customer) method in Python Write RemoveCustomer(Customer) method in


to add a new customer, considering it to act as a Python to remove a Customer, considering it to
PUSH operation of the stack datastructure. Also act as a POP operation of the stack datastructure.
display the contents of the Stack after PUSH Also return the value deleted from stack.
operation. Details of the Customer are : CID and
Name. def RemoveCustomer(Customer):
def AddCustomer(Customer): if Customer == [ ]:
cid = int(input(“Enter customer id:”)) print(“Underflow”)
Name = input(“Enter customer name:”)) else:
Customer.append ( [cid,Name] ) p = Customer.pop( )
return p

Write a function in python named PUSH(STACK, Write a function in python named POP(STACK)
SET) where STACK is list of some numbers where STACK is a stack implemented by a list of
forming a stack and SET is a list of some numbers. numbers. The function will display the popped
The function will push all the EVEN elements element after function call.
from the SET into a STACK implemented by using def POP(STACK):
a list. Display the stack after push operation. if STACK==[]:
def PUSH(STACK,SET): print(“underflow”)
for i in SET: else:
if i%2==0: print(STACK.pop())
STACK.append(i)
print(STACK)
Write a function in Python PUSH(Arr), where Arr Write a function in Python POP(Arr), where Arr is
is a list of numbers. From this list push all a stack implemented by a list of numbers. The
numbers divisible by 5 into a stack implemented function returns the value deleted from the
by using a list. Display the stack if it has at least stack.
one element, otherwise display appropriate error
message. def popStack(st) :
def PUSH(Arr,value): if len(st)==0:
s=[] print("Underflow")
for x in range(0,len(Arr)): else:
if Arr[x]%5==0: print(st.pop())
s.append(Arr[x])
if len(s)==0:
print("Empty Stack")
else:
print(s)
Write a function in Python PUSH (Lst), where Lst Write a function in python, PushEl(e) to add a
is a list of numbers. From this list push all new element and PopEl(e) to delete a element
numbers not divisible by 6 into a stack from a List ,considering them to act as push and
implemented by using a list. Display the stack if it pop operations of the Stack data structure .
has at least one element, otherwise display
appropriate error message. def PushEl(element):
def PUSH(Arr,value): a=int(input("enter package title : "))
s=[] element.append(a)
for x in range(0,len(Arr)):
if Arr[x]%6!=0: def PopEl(element):
s.append(Arr[x]) if (element==[]):
if len(s)==0: print( "Stack empty")
print("Empty Stack") else:
else: print (element.pop())
print(s)

Write InsertQ(C) and DeleteQ(C) Write a function DELQ(Customer) in Python to


methods/functions in Python to add a new delete a Customer from a Queue implemented
Customer and delete a Customer from a list of using list.
Customer names, considering them to act as
insert and delete operations of the Queue def DELQ(queue):
def InsertQ(queue): if (queue == []):
a=input(“Enter customer name :”) print (“Queue is empty…..”)
queue.append(a) else:
print(queue.pop(0))
def DeleteQ(queue):
if (queue==[]):
print (“Queue is empty…..”)
else:
print(queue.pop(0))

Write a function POP(Book) in Python to delete a Write a function in Python PushBook(Book) to


Book from a list of Book titles, considering it to add a new book entry as book_no and book_title
act as a pop operation of the Stack data in the list of Books , considering it to act as push
structure. operations of the Stack data structure.

def POP(Book): def PushBook(Book):


if (Book ==[]): bno = input("enter book no : ")
print(“Stack empty”) btitle = input(“enter book title:”)
else: rec = [bno , btitle]
print(Book.pop()) Book.append(rec)
print(Book)

You might also like