is there in C# some already defined generic container which can be used as Stack and as Queue at the same time? I just want to be able to append elements either to the end, or to the front of the queue
thanks
is there in C# some already defined generic container which can be used as Stack and as Queue at the same time? I just want to be able to append elements either to the end, or to the front of the queue
thanks
Here's my implementation of an immutable deque:
http://blogs.msdn.com/ericlippert/archive/2008/02/12/immutability-in-c-part-eleven-a-working-double-ended-queue.aspx
Notice that this is an immutable double-ended-queue. Normally you probably think of a queue as something you mutate:
An immutable queue always stays the same; when you add a new element, it gives you back an entirely new queue, so you use it as:
if you no longer care about the old value.
Good old
List<T>
will do it.Add()
to enqueue,Insert(0,T)
to push,Remove(0)
to pop/dequeue.Check the LinkedList class.
What you want is a linked list - there's one in the BCL - that has AddFirst and AddLast methods
Here's a class to help people implement this easily: