.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.

Advertisements

4 thoughts on “LIFO and FIFO (Stack and Queue)

  1. 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s