L18_PriorityQueue

L18_PriorityQueue - What are Priority Queues We introduce a...

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

View Full Document Right Arrow Icon
What are Priority Queues We introduce a new Data Structure called priority queues . A Queue: Page 1 of 44
Background image of page 1

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

View Full DocumentRight Arrow Icon
A Priority Queue E E N N Q Q U U E E U U E E Page 2 of 44
Background image of page 2
What are Priority Queues In computer science, we use priority queues to store val- ues. 10 8 7 4 3 3 4 7 10 10 8 priority enqueue 7 4 3 Priority queue of integers 23 15 6 4 2 4 6 23 15 2 4 priority dequeue 23 15 6 Priority queue of integers Page 3 of 44
Background image of page 3

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

View Full DocumentRight Arrow Icon
What are Priority Queues Of course, we also have priority queues of floats, priority queues of shapes, etc. , but we are not going to show them here. Priority queue of floats Priority queue of shapes Priority queue of Page 4 of 44
Background image of page 4
Priority Queue Operations The priority-enqueue operation inserts a new element at an ‘appropriate ’ position of a priority queue, according to the element’s priority . priority- enqueue Page 5 of 44
Background image of page 5

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

View Full DocumentRight Arrow Icon
Priority Queue Operations The priority-dequeue operation deletes and returns one element in a priority queue, which is always the element with the ‘smallest’ priority. f 44 Page 6 o priority- dequeue This element with the ‘smallest’ prior- ity is returned by priority-dequeue .
Background image of page 6
BIG DISCOVERY !!! A priority queue is NOT a queue. It is NOT a First-In-First-Out (FIFO) structure. Page 7 of 44 3 priority- enqueue 8 priority- enqueue 10 7 4 3 10 7 4 10 7 4 4 7 10 4 priority- dequeue 8 8 8 3 priority- dequeue 10 7 4 3 10 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
BIG DISCOVERY !!! In fact, we do not need to imagine that it is a queue at all! 3 priority- dequeue 10 4 7 8 Page 8 of 44
Background image of page 8
Defining a Priority Queue ADT As we always did, we see that PRIORITY QUEUE is an Abstract Data Type. priority- Equeue priority- Dequeue Page 9 of 44
Background image of page 9

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

View Full DocumentRight Arrow Icon
Following our tradition, we first write the file Priority- Queue interface class. Page 10 of 44
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 44

L18_PriorityQueue - What are Priority Queues We introduce a...

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

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