Advertisement
RAUL-SUAREZ

tp3-casoejemplo-b

Oct 25th, 2021
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
  3. //
  4.  
  5. /*
  6.  
  7. Escribir una función, método o subprograma que reciba como
  8. parámetros dos colas y devuelva una cola que resulte ser
  9. la unión de las otras dos. Se debe definir el mecanismo de
  10. “unión entre colas”, puede ser que la primera cola se encole
  11. detrás de la segunda, o que la segunda cola se encole después
  12. de la primera.
  13.  
  14.  */
  15.  
  16. import java.util.Random;
  17.  
  18. public class CasoEjemplo_b {
  19.  
  20.     private static Random random = new Random();
  21.  
  22.     public void Run() {
  23.  
  24.         System.out.println("Trabajo Práctico Nº 3 - Caso Ejemplo b)\n");
  25.  
  26.         Queue<Integer> queue1 = new Queue<Integer>(10);
  27.         Queue<Integer> queue2 = new Queue<Integer>(10);
  28.  
  29.         for (int cta = random.nextInt(10) + 1; cta > 0 ; --cta) {
  30.             queue1.offer(random.nextInt(500));
  31.         }
  32.         for (int cta = random.nextInt(10) + 1; cta > 0 ; --cta) {
  33.             queue2.offer(random.nextInt(500));
  34.         }
  35.  
  36.         System.out.println("cola 1.....: " + queue1.toString());
  37.         System.out.println("cola 2.....: " + queue2.toString());
  38.  
  39.         System.out.println("unión 1 - 2: " + Queue.union(queue1, queue2));
  40.  
  41.         System.out.println("unión 1 - 1: " + queue1.union(queue1).toString());
  42.         System.out.println("unión 1 - 2: " + queue1.union(queue2).toString());
  43.         System.out.println("unión 2 - 1: " + queue2.union(queue1).toString());
  44.         System.out.println("unión 2 - 2: " + queue2.union(queue2).toString());
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement