{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

6. Queues_outside

9 enqueue7 9 7 size 2 9 7 enqueue3 9 7 3 enqueue5 9 7

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

View Full Document Right Arrow Icon
(9) enqueue(7) (9 , 7) size() 2 (9 , 7) enqueue(3) (9 , 7 , 3) enqueue(5) (9 , 7 , 3 , 5) dequeue() (7 , 3 , 5) © 2010 Goodrich, Tamassia
Background image of page 3

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

View Full Document Right Arrow Icon
Queues 4 Applications of Queues Direct applications Waiting lists, bureaucracy Access to shared resources (e.g., printer) Multiprogramming Indirect applications Auxiliary data structure for algorithms Component of other data structures © 2010 Goodrich, Tamassia
Background image of page 4
Queues 5 Array-based Queue Use an array of size N in a circular fashion Three variables keep track of the front and rear f index of the front element r index immediately past the rear element n number of items in the queue Q 0 1 2 r f normal configuration Q 0 1 2 f r wrapped-around configuration © 2010 Goodrich, Tamassia
Background image of page 5

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

View Full Document Right Arrow Icon
Queues 6 Queue Operations Use n to determine size and emptiness Algorithm size () return n Algorithm empty () return ( n = 0 ) Q 0 1 2 r f Q 0 1 2 f r © 2010 Goodrich, Tamassia
Background image of page 6
7 Queue Operations (cont.) Algorithm enqueue ( o ) if size () = N 1 then throw QueueFull else Q [ r ] o r ( r + 1) mod N n n + 1 Operation enqueue
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page3 / 10

9 enqueue7 9 7 size 2 9 7 enqueue3 9 7 3 enqueue5 9 7 3 5...

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

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