Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UnirColasIntercalando {
- //----------Variables para toda la clase Tp03E3----------//
- public static int j,n;
- //-------------------Principal - main-------------------//
- public static void main(String[] args) {
- n=5;
- Cola<Character> cola1 = new Cola<Character>(n);
- Cola<Character> cola2 = new Cola<Character>(n);
- char cargar, continuar;
- do {
- System.out.println("Union Intercalada\n=================\nCargar 2 Colas\n------------------");
- for (int i=1; i<3; i++) {
- System.out.print("Cola "+i+": ");
- cargar=Helper.respuestaSN("¿Desea generar caracteres automaticamente?(S/N)");
- comoCargar(cargar, i, cola1, cola2);
- }
- System.out.println("Muestrario\n------------\nCola 1: " + cola1+"\nCola 2: " + cola2);
- System.out.println("La unión Intercalada entre Colas 1 y 2: " +unirColasIntercalando(cola1,cola2));
- continuar = Helper.respuestaSN("¿Desea realizar otra prueba? (S/N)");
- }while (continuar!='N');
- }
- //-------------------QueQue - Cargar--------------------//
- public static void comoCargar(char rta,int turno, Cola<Character> queque1,Cola<Character> queque2) {
- if (rta=='N') {
- if (turno==1) {
- CargarCaracter(queque1);
- }else {
- CargarCaracter(queque2);
- }
- }else {
- if (turno==1) {
- CargarRandomCola(queque1);
- }else {
- CargarRandomCola(queque2);
- }
- }
- }
- public static void CargarCaracter(Cola <Character> colaCaracteres) {
- char valor;
- for (j=0; j<n; j++) {
- valor=Helper.validarLetra();
- colaCaracteres.offer(valor);
- }
- }
- public static void CargarRandomCola(Cola<Character> randomcola ) {
- char letrarandom;
- for (j=0; j<n;j++) {
- letrarandom = Helper.letraRandom();
- randomcola.offer(letrarandom);
- }
- }
- //-------------QueQue - Unir (Ejercicio 3)--------------//
- public static Cola<Object> unirColasIntercalando(Cola<?> queque1 ,Cola<?> queque2){
- Cola<Object> auxiliar = new Cola<Object> (queque1.size()+queque2.size());
- while(!queque1.isEmpty()&& !queque2.isEmpty() ){
- auxiliar.offer(queque1.remove());
- auxiliar.offer(queque2.remove());
- }
- return auxiliar;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement