H32-Assign6Pqueue

H32-Assign6Pqueue - CS106B J Zelenski Handout #32 Feb 25,...

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

View Full Document Right Arrow Icon
CS106B Handout #32 J Zelenski Feb 25, 2008 Assignment #6: Priority Queue Due: Wed Mar 5th 2:15pm For this assignment, you will be implementing a class of your own: a priority queue, which is a variation on the standard queue. The standard queue processes element in the first-in, first-out ("FIFO") manner typical of ordinary waiting lines. Queues can be handy, but a FIFO strategy isn't always what's needed. A hospital emergency room, for example, needs to schedule patients according to priority. A patient with a more critical problem will pre-empt others even if they have been waiting longer. This is a priority queue , where elements are prioritized relative to each other and when asked to dequeue one, it is the highest priority element in the queue that is removed. There are many practice uses for a priority queue. 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, linked lists, and a special kind of tree called a heap. Once you have debugged your implementations, you will run some tests and consider the strengths and weaknesses of the various versions. We provide client code that tests and times the performance of the class, your role will be to act as the implementer only. The interface Ideally the priority queue would be written as a template class. However, given this is your first class implementation project, we're going to hold off on making it fully generic and instead use integer elements. This priority queue will store a collection of integers, where the integer itself is used as the priority. Larger integers are considered higher priority than smaller ones and are dequeued ahead of smaller values. Here is the basic priority queue interface: class PQueue { public: PQueue(); ~PQueue(); int size(); bool isEmpty(); void enqueue(int newElem); int dequeueMax(); }; Note the priority queue interface is quite similar to that of the ordinary queue. For the detailed specification of the behavior and usage of these functions, see the pqueue.h interface file included in the starter files. Just six member functions, how hard can that be? :-) Implementing the priority queue A priority queue can be implementing using a variety of data structures, each with different tradeoffs between memory required, runtime performance, complexity of code, etc. In this assignment, you will consider four different implementations. One implementation stores the queue elements in an unsorted vector. The second represents the priority queue as a sorted linked list. The third is a hybrid cross between an array and a linked list, a chunklist . The last represents the priority queue as specially-ordered binary tree called a heap (not to be confused with the heap where memory is dynamically allocated by new ). The first two implementations are provided to you pre-written, the last two will be yours to write.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Unsorted vector implementation The unsorted vector implementation is given to you. You do not have to write any code for this implementation, just go over and be familiar with the code provided. This implementation is layered
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 / 10

H32-Assign6Pqueue - CS106B J Zelenski Handout #32 Feb 25,...

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