Advertisement
LEANDRONIEVA

Ejercicio1

Oct 12th, 2022
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.LinkedList;
  3. import java.util.Queue;
  4.  
  5. public class Ejercicio1 {
  6.     public static int menu(){
  7.         Scanner op= new Scanner(System.in);
  8.        
  9.         System.out.println(" ****COLAS*****         ");
  10.         System.out.println("1. Ingresar caracter en la cola  ");
  11.         System.out.println("2. Quitar caracter de la cola    ");
  12.         System.out.println("3.  Mostrar Frente de la cola   ");
  13.         System.out.println("4. Mostrar Fin de la cola  ");
  14.         System.out.println("5.  Mostrar Cola ");
  15.         System.out.println("6. Quitar un elemento  ");
  16.         System.out.println("7.  Vaciar cola");
  17.         System.out.println("8. Bye Bye  ");
  18.         System.out.println("*************");
  19.         System.out.println(" Por favor elija una opcion: ");
  20.  
  21.         return op.nextInt();
  22.     }
  23.    
  24.     public static void quitarRepetido( colaCircular cola,Object aux )throws Exception{
  25.         Queue <Object> listaColaAux=new LinkedList <Object> ();
  26.         if (!cola.colaVacia()){
  27.             for (int i=cola.frente;i<=cola.fin;i++){
  28.                 if(cola.frenteCola()!=aux){
  29.                     listaColaAux.add(cola.frenteCola());
  30.                 }
  31.                 cola.frente=cola.siguiente(cola.frente);
  32.             }
  33.             System.out.print(listaColaAux);
  34.             System.out.println( " ");
  35.         }else throw new Exception(" Cola vacia");
  36.     }
  37.    
  38.     public static void main(String[]args ) throws Exception{
  39.         // TODO
  40.         colaCircular cola=new colaCircular();
  41.         char resp=' ';
  42.         int opcion;
  43.         Scanner lectura= new Scanner(System.in);
  44.         do{
  45.             opcion=menu();
  46.             switch (opcion) {
  47.             case 1:
  48.                 System.out.println(" Ingreses los caracteres a la cola  ");
  49.                 char o=lectura.nextLine().charAt(0);
  50.                 cola.insertar(o);
  51.                 break;
  52.             case 2:
  53.                 cola.quitar();
  54.                 break;
  55.             case 3:
  56.                 System.out.println("Frente de la cola: "+cola.frenteCola());
  57.                 break;
  58.             case 4:
  59.                 System.out.println("Fin de la cola: "+cola.finCola());
  60.                 break;
  61.             case 5:
  62.                 System.out.println("Tamaño de la cola: "+cola.tamañoCola()+1);
  63.                 System.out.println("COLA : ");
  64.                 cola.mostrarCola();
  65.                 break;
  66.             case 6:
  67.                 System.out.println("Quitar elemento  ");
  68.                 char num=lectura.nextLine().charAt(0);;
  69.                 quitarRepetido(cola,num);
  70.                 break;
  71.             case 7:
  72.                 cola.borrarCola();
  73.                 break;
  74.  
  75.             case 8:
  76.                 System.out.println("bye bye.....  ");
  77.                 break;
  78.             }
  79.         }while(opcion!=8);
  80.     }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement