24-Assignment-5-PQueue

24-Assignment-5-PQueue - CS106X Autumn 2010 Handout 24...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS106X Handout 24 Autumn 2010 October 25 th , 2010 Assignment 5: Priority Queue Assignment idea, handout, and binary heap implementation by Julie Zelenski. Binomial heaps by Jerry. So, it's finally time for you to be implementing a class of your own: a priority queue, which is a variation on the standard queue described in the reader. The standard queue is a collection of elements managed in a first-in, first-out manner. The first element added to the collection is always the first element extracted; the second is second; so on and so on. In some cases, a FIFO strategy may be too simplistic for the activity being modeled. A hospital emergency room, for example, needs to schedule patients according to priority. A patient who arrives with a more serious problem should pre-empt others even if they have been waiting longer. This is a priority queue , where elements are added to the queue in arbitrary order, but when time comes to extract the next element, it is the highest priority element in the queue that is removed. Such an object would be useful in a variety of situations. In fact, you can even use a priority queue to implement sorting; insert all the values into a priority queue and extract them one by one to get them in sorted order. The main focus of this assignment is to implement a priority queue class in several different ways. You'll have a chance to experiment with arrays and linked structures, and in doing so you’ll hopefully master the pointer gymnastics that go along with it. Optional Checkpoint Due i : Monday, November 1 st at 5:00 p.m. Final Submission Due: Monday, November 8 th at 5:00 p.m. The PQueue Interface The priority queue will be a collection of strings. Lexicographically smaller strings should be considered higher priority than lexicographically larger ones, so that "ping" is higher priority than "pong" , regardless of insertion order. Here are the methods that make up the public interface of all priority queues: class PQueue { public: void enqueue(string elem); string extractMin(); string peek(); static PQueue *merge(PQueue *one, PQueue *two); private: // implementation dependent member variables and helper methods }; i You can optionally submit the first two implementations (the unsoted vector, and the sorted list) by Monday at 5:00 p.m., and your section leader will look them over to confirm that thinks look to be going well. We strongly recommended you shoot for this, because linked lists will be on the November 3 rd midterm exam.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 enqueue is used to insert a new element to the priority queue. extractMin returns the value of highest priority (i.e., lexicographically smallest) element in the queue and removes it. merge destructively unifies the incoming queues and returns their union as a new queue. For the detailed descriptions on how these methods behave, see the pqueue.h interface file included in the starter files. Implementing the priority queue
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 16

24-Assignment-5-PQueue - CS106X Autumn 2010 Handout 24...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online