0% found this document useful (0 votes)
62 views3 pages

C# Cola

This document contains code for a C# program that implements a queue data structure and provides a menu-driven interface to perform common queue operations like enqueue, dequeue, check size, search, and display contents. The main function contains a switch statement to handle the selected menu option. Depending on the choice, it will add an element, remove one, clear the queue, check count, search for an item, or display all items currently in the queue.

Uploaded by

Mike Wasouski
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views3 pages

C# Cola

This document contains code for a C# program that implements a queue data structure and provides a menu-driven interface to perform common queue operations like enqueue, dequeue, check size, search, and display contents. The main function contains a switch statement to handle the selected menu option. Depending on the choice, it will add an element, remove one, clear the queue, check count, search for an item, or display all items currently in the queue.

Uploaded by

Mike Wasouski
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.Data.SqlTypes;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace guia_colas_3
{
class Program
{
static void Main(string[] args)
{
{
int op = 0;
int elam = 0;
bool elamB = false;
int cantidad = 0;
Queue<int> colasimple = new Queue<int>();
Random r = new Random();
try
{
do
{
Console.Clear();

Console.WriteLine("============================================");
Console.WriteLine(" QUEUE
");

Console.WriteLine("============================================");
Console.WriteLine(" 1.añadir un elemento a la cola
enqueue");
Console.WriteLine(" 2.sacar un elemto de la cola");
Console.WriteLine(" 3.vaciar cola");
Console.WriteLine(" 4.cantdad de elemtos en la cola ");
Console.WriteLine(" 5.buscar un elemto en la cola ");
Console.WriteLine(" 6.mostrar elementos de la cola ");
Console.WriteLine(" 0.salir");
Console.Write(" digite su opcion:--------->
");
op = int.Parse(Console.ReadLine());
Console.WriteLine(" ");

switch (op)
{
case 1:
{
elam = r.Next(100);
Console.WriteLine("\n\n elemto añadido:{0}",
elam);
colasimple.Enqueue(elam);
Console.ReadKey();
break;

}
case 2:
{
elam = colasimple.Dequeue();
Console.WriteLine("\n elemento que sale de la
cola es: {0}", elam);
Console.ReadKey();
break;

}
case 3:
{
colasimple.Clear();
break;
}
case 4:
{
cantidad = colasimple.Count;
Console.WriteLine("el queue tiene{0}",
cantidad);
Console.ReadKey();
break;
}
case 5:
{
try
{
Console.WriteLine("introducir el elemento a
buscar");
elam = int.Parse(Console.ReadLine());
elamB = colasimple.Contains(elam);
Console.WriteLine("se encontro:{0}",
elamB);
int p = 1;
foreach (int dato in colasimple)
{
if (dato == elam)
{
Console.WriteLine("El valor esta en
la posicion:" + p);
}
p = p + 1;
}
}
catch
{
Console.WriteLine("NO ES UN DATO VALIDO");
}

Console.ReadKey();
break;
}
case 6:
{
Console.WriteLine("");
foreach (int n in colasimple)
Console.Write("| {0}", n);
Console.ReadKey();
break;
}
}
} while (op != 0);
}
catch {
Console.WriteLine("NO SE ELIGIO UNA OPCION VALIDA");
}
}
}
}
}

You might also like