Queue

A queue is a first-in, first-out (FIFO) collection. Basic operations are Enqueue and Dequeue, respectively, to add an element to the end of the queue and to retrieve the first element in the queue. Compare this to a queue in the supermarket: If you’re in front, you’ll be served first. Figure 16.3 illustrates the principle of a queue’s operation.

Figure 16.3. Dequeue, Peek, and Enqueue operations on a queue data structure.

image

The following is a real-world example of a queue:

image

Because all collection types implement IEnumerable, you can enumerate ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.