0% found this document useful (0 votes)
4 views

Queue Using Built-in Functions

algoritn

Uploaded by

Min Shosho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Queue Using Built-in Functions

algoritn

Uploaded by

Min Shosho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Queue Using Built-in Functions

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Queue_1st_program
{
class Program
{
static void Main(string[] args)
{
Queue<int> My_Queue = new Queue<int>();
char C;
while (true)
{
Console.WriteLine("To add new value please press A");
Console.WriteLine("To search for a value please press S");
Console.WriteLine("To print all values please press P");
Console.WriteLine("To remove one value please press R");

C = char.Parse(Console.ReadLine());
if (C == 'A')
{
Console.Write("Enter the new value:");
My_Queue.Enqueue(int.Parse(Console.ReadLine()));
}
if (C == 'S')
{
Console.Write("Enter the value you would like to search for: ");
if (My_Queue.Contains(int.Parse(Console.ReadLine())))
Console.WriteLine("Found");
else
Console.WriteLine("Not Found");
}
if (C == 'P')
{
foreach (int x in My_Queue)
Console.Write(x + " ");
Console.WriteLine();
}
if (C == 'R')
{
if (My_Queue.Count == 0)
Console.WriteLine("No element in the the queue");
else
Console.WriteLine(My_Queue.Dequeue() + " is removed");

}
}
Console.ReadKey();
}

}
}

You might also like