Advertisement
FacuValverdi

EDTP03.-Ejercicio8

Oct 18th, 2019
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace EDTP03_EJ8
  9. {
  10.     class Program
  11.     {
  12.         public static int Comparar(Queue<int> cola1, Queue<int> cola2)
  13.         {
  14.             for (int i = 0; i < cola1.Count; i++)
  15.             {
  16.                 if (cola1.Peek() > cola2.Peek())
  17.                 {
  18.                     return 1;
  19.                 }
  20.                 else if (cola1.Peek() < cola2.Peek())
  21.                 {
  22.                     return -1;
  23.                 }
  24.                 cola1.Dequeue();
  25.                 cola2.Dequeue();
  26.             }
  27.             return 0;
  28.         }
  29.         static void Salida(int Resultado)
  30.         {
  31.             switch (Resultado)
  32.             {
  33.                 case 1:
  34.                     Console.WriteLine("La cola 1 es mayor que la cola 2");
  35.                     break;
  36.                 case -1:
  37.                     Console.WriteLine("La cola 1 es menor que la cola 2");
  38.                     break;
  39.                 case 0:
  40.                     Console.WriteLine("Las colas son iguales");
  41.                     break;
  42.             }
  43.  
  44.         }
  45.         static void Main(string[] args)
  46.         {
  47.             Queue<int> cola1 = new Queue<int>();
  48.             Queue<int> cola2 = new Queue<int>();
  49.             Console.WriteLine("Ingrese el tamaño de las colas:");
  50.             int tamaño = Int32.Parse(Console.ReadLine());
  51.             for (int i = 0; i < tamaño; i++)
  52.             {
  53.                 Console.WriteLine("Ingrese valor a agregar en la primera cola:");
  54.                 int valor1 = Int32.Parse(Console.ReadLine());
  55.                 cola1.Enqueue(valor1);
  56.             }
  57.             for (int k = 0; k < tamaño; k++)
  58.             {
  59.                 Console.WriteLine("Ingrese valor a agregar en la segunda cola:");
  60.                 int valor2 = Int32.Parse(Console.ReadLine());
  61.                 cola2.Enqueue(valor2);
  62.             }
  63.                 int Resultado = Comparar(cola1, cola2);
  64.                 Salida(Resultado);
  65.             Console.ReadKey();
  66.         }    
  67.     }        
  68.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement