[solved]-Using Python Write Queue Class Named Priorityqueue Start Listqueue Class Rewriting Modifyi Q39052016
Using Python,
Write a queue class named PriorityQueue. Start with theListQueue class, rewriting/modifying as needed.
The difference between PriorityQueue and ListQueue will be theaddition of a priority value associated with each item. This willbe done by using a private inner class storing the information anda priority value. So your data structure will not be a list ofstrings, or whatever data type we use in the main program. Yourdata structure will be a list of Nodes (using the example below),where each Node will contain the data type and priority value.
An example of the constructor might be:
class __Node:
def __init__ (self, item, priority):
self.item = item
#and whatever else you need to do in the constructor
The functionality of all methods will be identical to that ofthe ListQueue, with the exception of the enqueue method. Theenqueue method will accept a value to be added to the queue and anassociated priority value. This value will be between 1 and 100,with 100 being the highest priority. You will not have to performerror checking on the priority value. The enqueue method willinsert the object to be added BEFORE all items with a lowerpriority value. Another way to describe it is to say that theobject will be added AFTER all items with a higher OR equalpriority value. You do not have to worry about duplicate items, butthere will be different items with the same priority.
The constructor should create a list of 100 items by default. Itshould also allow for setting the size of the list. Create theentire list in the constructor.
Write a QueueException class. It doesn’t have to add any extrafunctionality to the class. We did this in class, if you arelooking for an example to follow.
def enqueue (itemToQueue = 1):
Adds itemToQueue to the queue with the specified priority value.The priority value can be “defaulted” to 1 if not specified. Throwa QueueException if there is an attempt to enqueue to a fullqueue.
def dequeue():
Removes and returns the “front” item from the queue. Take careto return the appropriate item. Throws a QueueException if there isan attempt to dequeue from an empty queue.
def isFull():
Returns True if the queue is full, otherwise returns False
def isEmpty():
Return True if the queue is empty, otherwise returns False
Write a test program to test the PriorityQueue class. An exampleof this could be:
queue1 = PriorityQueue (5)
queue1.enqueue (“a”, 90)
queue1.enqueue (“b”, 100)
queue1.enqueue (“c”, 100)
queue1.enqueue (“d”) # defaults to priority of 1
queue1.enqueue (“e”, 50)
try:
while not queue1.isEmpty():
temp = queue1.dequeue()
print (temp)
except QueueException as e:
print (“This will catch a dequeue error”)
except Exception as e:
print (“Error from something other than PriorityQueue”)
Expert Answer
Answer to Using Python, Write a queue class named PriorityQueue. Start with the ListQueue class, rewriting/modifying as needed. Th… . . .
OR

