EnqueueWithCapacity
Sometimes you may need a Queue
Source
public static void EnqueueWithCapacity<T>(this Queue<T> q, T item, int MaxSize)
{
if(q.Count >= MaxSize) q.Dequeue();
q.Enqueue(item);
}
Example
Queue<int> q = new Queue<int>();
q.EnqueueWithCapacity(0, 3); // {0}
q.EnqueueWithCapacity(1, 3); // {0, 1}
q.EnqueueWithCapacity(2, 3); // {0, 1, 2}
q.EnqueueWithCapacity(3, 3); // {1, 2, 3}
Author: David Harris
Submitted on: 21 aug 2010
Language: C#
Type: System.Collections.Generic.Queue<T>
Views: 3435