Dark Star1
Dark Star1

Reputation: 7403

What kind of Queues are lists and dictionaries?

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

Upvotes: 2

Views: 4381

Answers (3)

Patrick McDonald
Patrick McDonald

Reputation: 65431

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

Upvotes: 11

Meta-Knight
Meta-Knight

Reputation: 17875

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.

Upvotes: 9

Eric Smith
Eric Smith

Reputation: 5392

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.

Upvotes: 21

Related Questions