Advertisement
damarijsilva

Ejercicio3-opc1

Sep 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Ejercicio3
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Queue<int> queue1 = new Queue<int>();
  13.             Queue<char> queue2 = new Queue<char>();
  14.            
  15.  
  16.             Random random = new Random();
  17.  
  18.             Console.WriteLine("Cantidad de Elementos en la primer cola: ");
  19.             int l1 = Convert.ToInt16(Console.ReadLine());
  20.  
  21.             for (int c = 0; c < l1; c++)
  22.             {
  23.                 queue1.Enqueue(random.Next(0, 9));              
  24.             }
  25.  
  26.             Console.WriteLine("Cantidad de Elementos en la segunda cola: ");
  27.             int l2 = Convert.ToInt16(Console.ReadLine());
  28.             for (int c = 0; c < l2; c++)
  29.             {
  30.                 queue2.Enqueue((char)random.Next(65, 90));
  31.             }
  32.  
  33.  
  34.             Console.WriteLine("QUEUE 1");
  35.             foreach (int value in queue1)
  36.             {
  37.                 Console.WriteLine("|_{0}_|",value);
  38.             }
  39.  
  40.             Console.WriteLine("QUEUE 2");
  41.             foreach (char value in queue2)
  42.             {
  43.                 Console.WriteLine("|_{0}_|", value);
  44.             }
  45.  
  46.  
  47.             Console.WriteLine("Union entre colas -> [PressEnter]");
  48.             Console.ReadKey();
  49.             Console.Clear();
  50.             UnionColas(queue1, queue2);
  51.  
  52.             Console.ReadKey();
  53.            
  54.         }
  55.  
  56.  
  57.         public static void UnionColas(Queue<int> q1, Queue<char> q2)
  58.         {
  59.             Queue<object> Resultado = new Queue<object>();
  60.  
  61.             foreach (int value in q1)
  62.             {
  63.                 Resultado.Enqueue(value);
  64.             }
  65.  
  66.             foreach (char value in q2)
  67.             {
  68.                 Resultado.Enqueue(value);
  69.             }
  70.  
  71.             Console.WriteLine("UNION");
  72.             foreach (object value in Resultado)
  73.             {
  74.                 Console.WriteLine("|_{0}_|",value);
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement