Advertisement
MaTias0258

Untitled

Nov 9th, 2022
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class prueba {
  4.     ArbolAVL avl= new ArbolAVL();
  5.  
  6.     public void capturar(){
  7.         int dato;
  8.         dato=Integer.parseInt(JOptionPane.showInputDialog("Ingresa el numero: "));
  9.  
  10.         avl.insertar(dato);
  11.         JOptionPane.showMessageDialog(null,"Nodo "+dato+" agregado...");
  12.     }
  13.  
  14. public void imprimir(){
  15.     int d;
  16.      d=Integer.parseInt(JOptionPane.showInputDialog("ARBOL AVL\n\nIngrese una opcion: \nInOrden(1)\nPreOrden(2)\nPostOrden(3)"));
  17.                 switch(d){
  18.                     case 1:
  19.                         if(!avl.estaVacio()){
  20.                             System.out.println("Arbol en InOrden");
  21.                             avl.inOrden(avl.obtenerRaiz());
  22.                         }else{
  23.                             JOptionPane.showMessageDialog(null, "El arbol esta vacio");
  24.                         }
  25.                         break;
  26.                     case 2:
  27.                         if(!avl.estaVacio()){
  28.                             System.out.println("Arbol en PreOrden");
  29.                            avl.preorden(avl.obtenerRaiz());
  30.                         }else{
  31.                             JOptionPane.showMessageDialog(null, "El arbol esta vacio");
  32.                         }
  33.                         break;
  34.                     case 3:
  35.                         if(!avl.estaVacio()){
  36.                             System.out.println("Arbol en PostOrden");
  37.                           avl.postOrden(avl.obtenerRaiz());
  38.                         }else{
  39.                             JOptionPane.showMessageDialog(null, "El arbol esta vacio");
  40.                         }
  41.                         break;
  42.                 }
  43.                 JOptionPane.showMessageDialog(null, "Mostrado en consola...");
  44. }
  45.  
  46.     public static void main(String[] args) {
  47.         prueba clase = new prueba();
  48.      int r=0;
  49.  
  50.         do{
  51.         r=Integer.parseInt(JOptionPane.showInputDialog("Ingrese una opcion: \nIngresar(1)\nImprimir(2)\nSalir(3)"));
  52.         switch(r){
  53.             case 1:
  54.               clase.capturar();
  55.                 break;
  56.             case 2:
  57.          clase.imprimir();
  58.                 break;
  59.             case 3:
  60.                 JOptionPane.showMessageDialog(null, "Gracias");
  61.                 break;
  62.             default:JOptionPane.showMessageDialog(null, "La opcion esta incorrecta");
  63.         }
  64.         }while(r!=3);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement