Question: python 1. Priority Queue Implementation 3 Write an implementation of Priority Queue using List. The following methods of queue will be implemented 1. Enqueue (queue,

python python 1. Priority Queue Implementation 3 Write an implementation of Priority Queue

1. Priority Queue Implementation 3 Write an implementation of Priority Queue using List. The following methods of queue will be implemented 1. Enqueue (queue, item, priority): will add the tuple (item, priority) to the queue. You should keep the queue in descending order of priority. If multiple items have same priority, their natural ordering will be retained 2. Dequeue (queue): will return the item at the front of the queue. Since the queue is in sorted order, the highest priority item will be dequeued Language: Python 3 Autocomplete Ready I v import ast 2 queue - input queue ast. literal eval(queue) 5 def Enqueue (queue, item, priority): 5 pass 7 8 def Dequeue queue): 9 pass 10 11 operation = input() 12 13 If operation == "Enqueue": item = input() 15 priority = int(input) 16 Enqueue (queue, item, priority) 17 print (queue) 18 elif operation "Dequeue": 19 print (Dequeue (queue)) 20 print (queue)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!