Initializing queues
Each language provides varying levels of support for the queue data structure. Here are some examples of initializing the collection, adding an object to the back of the collection, and then removing the head object from the head of the collection.
C#
C# provides a concrete implementation of the queue data structure through the Queue<T>
generic class:
Queue<MyObject> aQueue = new Queue<MyObject>(); aQueue.Enqueue(anObject); aQueue.Dequeue();Java
Java provides the abstract Queue<E>
interface, and several concrete implementations of the queue data structure use this interface. Queue is also extended to the Deque<E>
interface that represents a double-ended queue. The ArrayDeque<E>
class is one concrete implementation of the Deque<E>
interface:
ArrayDeque<MyObject> aQueue = new ArrayDeque<MyObject>(); aQueue.addLast(anObject); aQueue.getFirst();
Objective-C
Objective-C does not provide a concrete...