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.

3 Responses

  1. I think there is a slight typo above Queue is FIFO and Stack is LIFO

  2. Shoot overlooked it. I have updated it accordingly. Thanks!

  3. hello,
    I need some help in VB.NET 2008 if anyone here can help me to produce reporting of invoices which means when i enter a customers code, the invoices and the total amount is calculated and shown on screen and from there i can print.
    Please answer me

Leave a Reply