Advertisement
Guest User

Ejercicio 8

a guest
Oct 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace tp3e8
  5. {
  6.     public class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             int l, c, j;
  11.             Queue<int> cola1 = new Queue<int>();
  12.             Queue<int> cola2 = new Queue<int>();
  13.             Console.WriteLine("Ingrese el tamaño que tendran las colas");
  14.             c = Int32.Parse(Console.ReadLine());
  15.             Console.WriteLine("Ingrese los valores para la 1° Cola");
  16.             for (j = 0; j < c; j++)
  17.             {
  18.                 l = Int32.Parse(Console.ReadLine());
  19.                 cola1.Enqueue(l);
  20.             }
  21.             Console.WriteLine("Ingrese los valores para la 2° Cola");
  22.             for (j = 0; j < c; j++)
  23.             {
  24.                 l = Int32.Parse(Console.ReadLine());
  25.                 cola2.Enqueue(l);
  26.             }
  27.             c = CompararColas(cola1, cola2);
  28.             switch (c)
  29.             {
  30.                 case 1:
  31.                     Console.WriteLine("La 1° Cola es MAYOR que la 2° Cola");
  32.                     break;
  33.                 case -1:
  34.                     Console.WriteLine("La 1° Cola es MENOR que la 2° Cola");
  35.                     break;
  36.                 case 0:
  37.                     Console.WriteLine("Las Colas son IGUALES");
  38.                     break;
  39.             }
  40.         }
  41.         public static int CompararColas(Queue<int> cola1, Queue<int> cola2)
  42.         {
  43.             for (int i = 0; i < cola1.Count; i++)
  44.             {
  45.                 if (cola1.Peek() > cola2.Peek())
  46.                 {
  47.                     return 1;
  48.                 }
  49.                 else if (cola1.Peek() < cola2.Peek())
  50.                 {
  51.                     return -1;
  52.                 }
  53.                 cola1.Dequeue();
  54.                 cola2.Dequeue();
  55.  
  56.             }
  57.             return 0;
  58.  
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement