tags:

views:

213

answers:

3

I'm just wondering what kind of queues are lists and dictionaries in C#. Whether they're FIFOs or LIFOs.

+18  A: 

Lists and dictionaries are containers that don't support a queue model, that is, they're neither LIFO nor FIFO. Put another way, you're not comparing apples with apples.

Eric Smith
Put another way, you haven't even Googled (or Binged)
Jeff Yates
+7  A: 

Dictionaries and lists aren't queues, and also FIFO and LIFO doesn't apply to C# lists and dictionaries. You can add/remove items anywhere in a list. You can also add/remove any entry in a dictionary. Not only at the beginning or at the end. Also, a dictionary isn't ordered so there is not even a concept of a beginning and an end.

Meta-Knight
To extend this further, the documentation for Dictionary<TKey, TValue> actually states that the items are unordered and can be returned in any order when enumerating.
KeeperOfTheSoul
+9  A: 

In C#, if you want a LIFO (stack) use System.Collections.Generic.Stack, and if you want a FIFO (queue) use System.Collections.Generic.Queue

Patrick McDonald
Most grateful for pointing me in the right direction.
Dark Star1