The Queue<T> collection
A queue is a linear data structure where insertion and deletion of elements is performed from two different ends. A new item is added from the rear end of the queue and deletion of existing items occurs from the front. Therefore, the item to be inserted first will be the item to be deleted first. Because of this, the queue is called a First in, First Out (FIFO) collection. The following diagram depicts a queue, where Enqueue represents adding an item to the queue and Dequeue represents deleting an item from the queue:
In .NET, the class that implements a generic queue is Queue<T>
. Similarly, with Stack<T>
, there are overloaded constructors that allow us to create an empty queue or a queue initialized with elements from an IEnumerable<T>
collection. Take a look at the following code snippet, where we are creating a queue of strings with three initial...