Advertisement
damarijsilva

Ejer5

Sep 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using TP3;
  6.  
  7. namespace Ejercicio5
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("Cantidad de elementos en la cola: ");
  14.             int lng = Convert.ToInt16(Console.ReadLine());            
  15.             Cola<int> queue1 = new Cola<int>(lng);
  16.  
  17.             for (int c = 0; c < lng; c++)
  18.             {
  19.                 Console.Write("Elemento nĀ°{0}: ",c+1);
  20.                 queue1.Enqueue(Convert.ToInt16(Console.ReadLine()));
  21.             }
  22.             Console.Clear();
  23.  
  24.             Console.WriteLine("Cola cargada: ");
  25.  
  26.             for (int c = 0; c < lng; c++)
  27.             {
  28.                 if(queue1.Datos[c] < 10)
  29.                     Console.WriteLine("|_{0}{1}_|", '0', queue1.Datos[c]);
  30.                 else
  31.                     Console.WriteLine("|_{0}_|", queue1.Datos[c]);
  32.             }
  33.  
  34.             Console.Write("\r\nIngrese un valor que desee suprimir: ");
  35.             Suprimir(ref queue1, Convert.ToInt16(Console.ReadLine()));
  36.  
  37.             if (!queue1.Empty)
  38.             {
  39.                 Console.WriteLine("\r\nCola con Valor Suprimido: ");
  40.                 for (int c = 0; c < queue1.Datos.Length; c++)
  41.                 {
  42.                     if (queue1.Datos[c] < 10)
  43.                         Console.WriteLine("|_{0}{1}_|", '0', queue1.Datos[c]);
  44.                     else
  45.                         Console.WriteLine("|_{0}_|", queue1.Datos[c]);
  46.                 }
  47.             }
  48.             else
  49.                 Console.Write("\r\nNo quedaron elementos sin suprimir");
  50.             Console.ReadKey();
  51.         }
  52.  
  53.  
  54.         public static void Suprimir(ref Cola<int> q, int v)
  55.         {
  56.             int cont = 0;
  57.             for (int c = 0; c < q.Datos.Length; c++)
  58.             {
  59.                 if (q.Datos[c] != v)
  60.                     cont++;      
  61.             }
  62.             Cola<int> q2 = new Cola<int>(cont);
  63.  
  64.             while (!q.Empty)
  65.             {
  66.                 if (q.Peek() != v)
  67.                 {
  68.                     q2.Enqueue(q.Peek());
  69.                     q.Dequeue();
  70.                 }
  71.                 else
  72.                     q.Dequeue();
  73.             }
  74.             q = q2;
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement