.net, Code, Microsoft, Technical, Visual Studio

LIFO and FIFO (Stack and Queue)

Well, I was working on one of the projects which required the use of the FIFO and LIFO data structures. Since the project was based on .NET, I had no trouble at all implementing the same.

The System.Collections namespace provides us with the classes required to implement FIFO and LIFO.

Declare the queue:
Queue myQ = new Queue(5);
To add an item:
myQ.Enqueue(“myItem”);
To remove an item:
myQ.Dequeue();

For LIFO:
Declare the Stack:
Stack myStack = new Stack(5);
To add an item:
myStack.Push(“myItem”);
To remove an item:
myStack.Pop();

Gone are the days where one has to write the entire code to implement these oft used operations.