Data Structures - Lab 09

Tuesday, October 20th

Creating a Priority Queue from an Array-based Queue


The Lab

For some of you, this lab will be trivial.  For others, you will struggle.  The point is to see if you can do this, and if you DO struggle, have you struggle in a situation where I am around to help.

 

Yesterday, in lecture, we talked about the concept of a priority queue made from a Linked Queue.  To demonstrate this idea please download the following code:

To demonstrate this code load the linkedPriorityQueue.py file (remember that "loading" is done via a menu option or the F5 key).  Once you have done this type in the following commands

>>>  from printJob import PrintJob
>>>  q = LinkedPriorityQueue()
>>>  q.enqueue(PrintJob("W",3))
>>>  q.enqueue(PrintJob("A",1))
>>>  q.enqueue(PrintJob("X",3))
>>>  q.enqueue(PrintJob("Y",3))
>>>  q.enqueue(PrintJob("B",1))
>>>  q.enqueue(PrintJob("J",2))
>>>  print q

At this point, you should make sure that the order of the queue printed makes sense to you.  Make sure that you spend some time looking at the code for the LinkedPriorityQueue and ask questions now if you don't understand what is happening.

 

Next, download the file for the original Array-based queue distributed by your author.

Open this in IDLE and save this as a new file:

 

Using LikedPriorityQueue as a model, add a NEW class to this new file called ArrayPriorityQueue.  This class should allow the user to create a priority queue built on top of this Array based implementation. 

To test your code you should type in the following commands

>>>  q = ArrayPriorityQueue()
>>>  q.enqueue(PrintJob("W",3))
>>>  q.enqueue(PrintJob("A",1))
>>>  q.enqueue(PrintJob("X",3))
>>>  q.enqueue(PrintJob("Y",3))
>>>  q.enqueue(PrintJob("B",1))
>>>  q.enqueue(PrintJob("J",2))
>>>  print q

The results should be identical to what you obtained with the LinkedPriorityQueue above.

 


To get credit for this assignment you should submit your final linkedPriorityQueue.py via the homework submission system no later than the start of class on Wednesday.

 

If you finish prior to the end of class you may leave or you may stick around and work on PA#4.