Chapter16 - Chapter 16 Queues A queue is first-in first-out...

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

View Full Document Right Arrow Icon
A “queue” is “first-in first-out” (FIFO) data structure. Queues are analogous to the lineups at bank machines and elsewhere (indeed, in Britain, such lineups are called queues). Basic queues support only two operations. An “enqueue” adds an item to the queue and a “dequeue” removes an item. Queues are used in all kinds of applications. A printer spooler will typically maintain a queue of jobs awaiting printing. In a multi-tasking environment, a “producer” task will often use a “queuer” in transferring data to a “consumer” task. And so on, and so on… The following template class declaration outlines the functionality of queues. template <class T> class Queue { public: Queue (int capacity); void enqueue (T item); // throws “overflow_error” if no space for item T dequeue (); // throws “overflow_error” if queue is empty int size (); // returns number of items in queue T look (); // as for dequeue but item is left in queue }; Queue
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/24/2010 for the course SYSC 2002 taught by Professor Unknown during the Fall '07 term at Carleton.

Page1 / 4

Chapter16 - Chapter 16 Queues A queue is first-in first-out...

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

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