70-536 exam: Queue class
13 March 2010
Queues are a very popular data structure for both in memory processes and also database physical design. Starting with a quick summary from Wikipedia:
A queue (pronounced /kju:/) is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data structure.
Source: Wikipedia

Source: Wikipedia
Within .NET framework, Queues are in the Generic collections namespace and system.dll
Namespace: System.Collections.Generic Assembly: System (in System.dll)
and implement the IEnumerable and ICollection interfaces:
[SerializableAttribute] [ComVisibleAttribute(false)] public class Queue: IEnumerable , ICollection, IEnumerable
Note:
The following basic code example starts by creating and populating a Queue of string elements, I then iterate through the elements
Queuesupported_languages = new Queue (); supported_languages.Enqueue("English"); supported_languages.Enqueue("French"); supported_languages.Enqueue("German"); supported_languages.Enqueue("Swedish"); supported_languages.Enqueue("Finnish"); supported_languages.Enqueue("Italian"); foreach (string language in supported_languages) { Console.WriteLine(language); }
this returns:
English French German Swedish Finnish Italian
Now support FIFO operations as well as the enqueue method above, we also have dequeue and peek methods:
Console.WriteLine("\nDequeuing '{0}'", supported_languages.Dequeue());
Console.WriteLine("Peek at next item to dequeue: {0}", supported_languages.Peek());
Console.WriteLine("Dequeuing '{0}'", supported_languages.Dequeue());
this returns:
Dequeuing 'English' Peek at next item to dequeue: French Dequeuing 'French'
If you liked this blog post, you may want to subscribe to my news feed in your RSS reader.
