Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

Here is the previous code based on based on the built-in List module. Now queue needs to be implemented using linked lists

from random import randint

class Customer: def __init__(self,n): self.numberOfItems=n

def __str__(self): return str(self.numberOfItems)

def getNumberOfItems(self): return self.numberOfItems

class 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

#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)

customersQueue = Queue() totalCustomers = 30 #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======

#CheckOut========================== totalTime=0 totalCustomers = customersQueue.size() while not(customersQueue.isEmpty()): #A customer gets to the checkout every 1 5 minutes totalTime+=randint(1,5)

#Picking a customer customer = customersQueue.dequeue()

#Processing the customer timeTaken = checkOut(customer)

totalTime+=timeTaken #====================================

#Result============================= averageWaitTime = totalTime/totalCustomers print("Average wait time is "+str(averageWaitTime)+" minutes") print("The number of customers left in the queue is ", customer)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago