Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using TP3;
- namespace Ejercicio5
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Cantidad de elementos en la cola: ");
- int lng = Convert.ToInt16(Console.ReadLine());
- Cola<int> queue1 = new Cola<int>(lng);
- for (int c = 0; c < lng; c++)
- {
- Console.Write("Elemento nĀ°{0}: ",c+1);
- queue1.Enqueue(Convert.ToInt16(Console.ReadLine()));
- }
- Console.Clear();
- Console.WriteLine("Cola cargada: ");
- for (int c = 0; c < lng; c++)
- {
- if(queue1.Datos[c] < 10)
- Console.WriteLine("|_{0}{1}_|", '0', queue1.Datos[c]);
- else
- Console.WriteLine("|_{0}_|", queue1.Datos[c]);
- }
- Console.Write("\r\nIngrese un valor que desee suprimir: ");
- Suprimir(ref queue1, Convert.ToInt16(Console.ReadLine()));
- if (!queue1.Empty)
- {
- Console.WriteLine("\r\nCola con Valor Suprimido: ");
- for (int c = 0; c < queue1.Datos.Length; c++)
- {
- if (queue1.Datos[c] < 10)
- Console.WriteLine("|_{0}{1}_|", '0', queue1.Datos[c]);
- else
- Console.WriteLine("|_{0}_|", queue1.Datos[c]);
- }
- }
- else
- Console.Write("\r\nNo quedaron elementos sin suprimir");
- Console.ReadKey();
- }
- public static void Suprimir(ref Cola<int> q, int v)
- {
- int cont = 0;
- for (int c = 0; c < q.Datos.Length; c++)
- {
- if (q.Datos[c] != v)
- cont++;
- }
- Cola<int> q2 = new Cola<int>(cont);
- while (!q.Empty)
- {
- if (q.Peek() != v)
- {
- q2.Enqueue(q.Peek());
- q.Dequeue();
- }
- else
- q.Dequeue();
- }
- q = q2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement