Queues

A queue is a data structure that can be presented using the example of a line of people waiting in a shop at the checkout. New people stand at the end of the line, and the next person is taken to the checkout from the beginning of the line. You are not allowed to choose a person from the middle and serve him or her in a different order.

The queue data structure operates in exactly the same way. You can only add new elements at the end of the queue (the enqueue operation) and remove an element from the queue only from the beginning of the queue (the dequeue operation). For this reason, this data structure is consistent with the FIFO principle, which stands for First-In First-Out. In the example regarding a line of people waiting in ...

Get C# Data Structures and Algorithms 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.