Queues 4 applications of queues direct applications

Info icon This preview shows pages 4–9. Sign up to view the full content.

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
Image of page 4

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

View Full Document Right Arrow Icon
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
Image of page 5
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
Image of page 6

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

View Full Document Right Arrow Icon
Queues 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 throws an exception if the array is full This exception is implementation- dependent Q 0 1 2 r f Q 0 1 2 f r © 2010 Goodrich, Tamassia
Image of page 7
Queues 8 Queue Operations (cont.)
Image of page 8

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern