What are some good, simple examples for queues?

Posted by Michael Ekstrand on Programmers See other posts from Programmers or by Michael Ekstrand
Published on 2012-06-22T15:40:24Z Indexed on 2012/06/22 21:25 UTC
Read the original article Hit count: 252

Filed under:
|
|

I'm teaching CS2 (Java and data structures), and am having some difficulty coming up with good examples to use when teaching queues. The two major applications I use them for are multithreaded message passing (but MT programming is out of scope for the course), and BFS-style algorithms (and I won't be covering graphs until later in the term).

I also want to avoid contrived examples. Most things that I think of, if I were actually going to solve them in a single-threaded fashion I would just use a list rather than a queue. I tend to only use queues when processing and discovery are interleaved (e.g. search), or in other special cases like length-limited buffers (e.g. maintaining last N items). To the extent practical, I am trying to teach my students good ways to actually do things in real programs, not just toys to show off a feature.

Any suggestions of good, simple algorithms or applications of queues that I can use as examples but that require a minimum of other prior knowledge?

© Programmers or respective owner

Related posts about data-structures

Related posts about teaching