Data Structure Test 5
Q1. Write queueadd(clientname) and queuedel(clientname) methods in python to add a new client and delete a client from a list of Client Names, considering them to act as an insert and delete operations of the queue data structure.
Ans.
cn=[]
def queueadd(cn):
cname=input("Enter Client Name")
cn.append(cname)
def queuedel(cn):
if(len(cn)==0):
print("Queue is Empty")
else:
print("Deleted element is", cn[0])
del cn[0]
#you can call the following functions to verify
the above code
queueadd(cn)
queueadd(cn)
queueadd(cn)
queuedel(cn)
print(cn)
Q2. Write queueadd(pid) and queuedel(pid) methods in python to add a new product and delete a product from a list of product id, considering them to act as an insert and delete operations of the queue data structure. (Consider product id of integer type)
Ans.
pid=[]
def queueadd(cn):
prid=int(input("Enter Product id"))
cn.append(prid)
def queuedel(pid):
if(len(pid)==0):
print("Queue is Empty")
else:
print("Deleted element is", pid[0])
del pid[0]
#you can call the following functions to verify
the above code
queueadd(pid)
queueadd(pid)
queueadd(pid)
queuedel(pid)
print(pid)
Q3. Write add(book) and del1(book) methods in python to add a new book and delete a book from a list of book name, considering them to act as an insert and delete operations of the queue data structure.
Ans.
book=[]
def add(book):
bn=input("Enter book name")
book.append(bn)
def del1(book):
if(len(book)==0):
print("Queue is Empty")
else:
print("Deleted element is", book[0])
del book[0]
#you can call the following functions to verify
#the above code
add(book)
add(book)
add(book)
del1(book)
print(book)
Q4. Write addq(Employee) and delq(Employee) methods in python to add a new Employee Name and delete an Employee from a list of Employee name, considering them to act as an insert and delete operations of the queue data structure.
Ans.
emp=[]
def addq(emp):
en=input("Enter employee name")
emp.append(en)
def delq(emp):
if(len(emp)==0):
print("Queue is Empty")
else:
print("Deleted element is", emp[0])
del emp[0]
#you can call the following functions to verify
#the above code
addq(emp)
addq(emp)
addq(emp)
delq(emp)
print(emp)
Q5. Write adding(Rollno) and deleting(Rollno) methods in python to add a new Roll Number and delete Roll Number from a list of Roll Number, considering them to act as an insert and delete operations of the queue data structure. (Roll number is of type integer
Ans.
rno=[]
def adding(rno):
rn=int(input("Enter Roll Number"))
rno.append(rn)
def deleting(rno):
if(len(rno)==0):
print("Queue is Empty")
else:
print("Deleted element is", rno[0])
del rno[0]
#you can call the following functions to verify
#the above code
adding(rno)
adding(rno)
adding(rno)
deleting(rno)
print(rno)