First In First Out(FIFO) Implementation

Write a program to demonstrate First In First Out(FIFO) approach.

Solution:

using System;
using System.Collections.Generic;

namespace QueueOperation
{
    class Program
    {
        static void Main()
        {
            var queue = new Queue<int>();
            Console.WriteLine("Enter 5 elements");
            for (var i = 0; i < 5; i++)
                queue.Enqueue(Convert.ToInt32(Console.ReadLine()));

            Console.WriteLine("Elements of queue");
            foreach (var s in queue)
                Console.Write(s + "\t");

            Console.WriteLine();
            Console.WriteLine("Dequeue a elements");
            var dequeueItem = queue.Dequeue();
            Console.Write(dequeueItem + "\t");

            Console.WriteLine();
            Console.WriteLine("Elements of queue");

            foreach (var s in queue)
                Console.Write(s + "\t");

            Console.ReadLine();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *