Is there a double sided stack class in .net?
Why not just use/wrap LinkedList<T>
? It has AddFirst
and AddLast
methods. You can wrap it to hide the AddBefore
etc. methods.
The common term for this is deque (it means double ended queue). If for some reason wrapping a LinkedList<T>
doesn't suffice (it should!), you could look at Eric Lippert's implementation of an immutable deque.
What you are looking for is a deque. Here is an example: http://www.codeproject.com/KB/recipes/deque.aspx
It sounds like you want something normally called a deque. The closest I'm aware of in .NET is LinkedList<T>
. I don't believe there's one built from a circular buffer (expanding as required), which is the way you'd probably want to build it from scratch.
Of course, you could implement it yourself - but I'd probably use LinkedList<T>
unless I had a really good reason not to. Eric Lippert also has an immutable implementation you could look at (see his blog post covering it), but obviously you'd want to write a bunch of tests etc... and you may not want an immutable one.