Queue

Queues maintain a collection of items in a First In First Out (FIFO) order. The item inserted into the queue first is retrieved first from the queue. Only three operations are allowed in queues, namely Enqueue, Dequeue, and Peek.

Enqueue adds an element to the end of the queue, whereas Dequeue removes the element from the start of the queue. Peek returns the oldest elements in the queue but does not remove them:

The preceding diagram illustrates how items are added to the queue. The item inserted first will be removed first from the queue and the pointer moves to the next item in the queue. Peek always returns the first item that was ...

Get C# 7 and .NET Core 2.0 High Performance 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.