Question
The Queue that we created in class was based on the built-in List module in Python. The Queue class can also be based on the
The Queue that we created in class was based on the built-in List module in Python. The Queue class can also be based on the Linked List structure discussed in class. For this assignment, implement a queue using linked lists. Use the methods created for the list based queue as a guide. You will need to decide which end to set up as front and which end to set up as back. Be sure to include all the methods that are in the list based queue. Also, write a test program to test your new queue. Be sure to include enough code to test all the methods and write the code in such a way that whoever is looking at the output (me) will be able to understand what the program is doing.
_____________________________________________________________________________________
Following is the code of the queue done in previous class..
#import random function from random import randint #class Queue declaration class Queue: #declare methods in the Queue def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def enqueue(self, item): self.items.insert(0, item) def dequeue(self): return self.items.pop() def size(self): return len(self.items) def getInnerList(self): return self.items #customer Queue class Customer: #declare methods def __init__(self,n): self.numberOfItems=n def __str__(self): return str(self.numberOfItems) def getNumberOfItems(self): return self.numberOfItems #expresscheker customer queue class Expresschecker: def __init__(self,n): self.numberOfItems=n def __str__(self): return str(self.numberOfItems) def getNumberOfItems(self): return self.numberOfItems #Returns random checkout time, based on number of items def checkOut(Expresschecker): items = Expresschecker.getNumberOfItems() if items <= 10: return randint(2, 5) if items <= 20: return randint(6, 9) return randint(10, 14) #Initiate queue for the Expresschecker Expresschecker = Queue() #declare total customers totalcheckoutCustomers = 10 #express Customers shopping.. for i in range(totalcheckoutCustomers): randomItemsQty = randint(1, 25) customer = Customer(randomItemsQty) #Getting into queue for checkout Expresschecker.enqueue(customer) #intial time totalTime=0 #define the size of the queue totalcheckoutCustomers = Expresschecker.size() #check out the items in the express cheker queue while not(Expresschecker.isEmpty()): totalTime+=randint(1,5) #Picking a customer expresscustomer = Expresschecker.dequeue() #Processing the customer timeTaken = checkOut(expresscustomer) #add the time for each custimer totalTime+=timeTaken #compute average waiting time averageWaitingTime = totalTime/totalcheckoutCustomers #display the average waiting time print("Average waiting time for the express customer queue is " +str(averageWaitingTime)+" minutes ") print("Remaining Custimers in the express customer Queue is: ", Expresschecker.size()) #Returns random checkout time, based on number of items def checkOut(customer): items = customer.getNumberOfItems() if items <= 10: return randint(1, 5) if items <= 20: return randint(6, 10) return randint(11, 15) #in customersQueue = Queue() totalCustomers = 20 #Change number of customers here #Customers shopping.. for i in range(totalCustomers): #Each putting Between 1 to 25 items randomItemsQty = randint(1, 25) customer = Customer(randomItemsQty) #Getting into queue for checkout customersQueue.enqueue(customer) #Now all Customers having random qty of items are in queue totalTime=0 totalCustomers = customersQueue.size() while not(customersQueue.isEmpty()): totalTime+=randint(1,5) #Picking a customer customer = customersQueue.dequeue() #Processing the customer timeTaken = checkOut(customer) totalTime+=timeTaken averageWaitTime = totalTime/totalCustomers print("Average wait time for the customer queue is "+str(averageWaitTime)+" minutes ") print("Remaining Customers in the customer Queue is: ",customersQueue.size())
________________________________________________________________________________________
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started