Advertisement
Mitoeap

ABBClaPrin

Jun 23rd, 2020
2,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 4.11 KB | None | 0 0
  1.  
  2. package arbolbb;
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class ArbolBB {
  8.  
  9.    
  10.     public static void main(String[] args) {
  11.         int opcion=0;
  12.         int dato;
  13.         Scanner sc = new Scanner(System.in);
  14.         ArbolBinB arb = new ArbolBinB();
  15.         do{
  16.             try{
  17.                 System.out.println("");
  18.                 System.out.println("1. Agregar Nodo");
  19.                 System.out.println("2. Reocorrer el Arbol In Order");
  20.                 System.out.println("3. Reocorrer el Arbol Pre Order");
  21.                 System.out.println("4. Reocorrer el Arbol Pos Order");
  22.                 System.out.println("5. Buscar un Nodo en el Arbol");
  23.                 System.out.println("6. Numero de Nodos del Arbol");
  24.                 System.out.println("7. Numero de Nodos Hoja del Arbol");
  25.                 System.out.println("8. Nivel del Arbol");
  26.                 System.out.println("9. Altura del Arbol");
  27.                 System.out.println("10. Recorrido Descendente");
  28.                 System.out.println("11. Salir");
  29.                 System.out.print("Ingrese opcion ==> ");
  30.                 opcion = sc.nextInt();
  31.                 switch (opcion){
  32.                     case 1:
  33.                         System.out.println("Ingrese dato");
  34.                         dato = sc.nextInt();
  35.                         arb.agregarNodo(dato);
  36.                         break;
  37.                     case 2:
  38.                         if (!arb.estaVacio()) {
  39.                             arb.inOrder(arb.raiz);
  40.                         }else{
  41.                             System.out.println("El Arbol está vacio");
  42.                         }
  43.                         break;
  44.                     case 3:
  45.                         if (!arb.estaVacio()) {
  46.                             arb.preOrder(arb.raiz);
  47.                         }else{
  48.                             System.out.println("El Arbol está vacio");
  49.                         }
  50.                         break;
  51.                     case 4:
  52.                         if (!arb.estaVacio()) {
  53.                             arb.posOrder(arb.raiz);
  54.                         }else{
  55.                             System.out.println("El Arbol está vacio");
  56.                         }
  57.                         break;
  58.                     case 5:
  59.                         if (!arb.estaVacio()) {
  60.                             System.out.println("Ingrese valor a buscar en el Arbol:");
  61.                             NodoArbol busNod = arb.buscarNodo(sc.nextInt());
  62.                             if (busNod == null) {
  63.                                 System.out.println("El valor no esta en el Arbol");
  64.                             }else{
  65.                                 System.out.println("El valor "+busNod.Dato+" esta en el Arbol");
  66.                             }
  67.                            
  68.                         }else{
  69.                             System.out.println("El Arbol está vacio");
  70.                         }
  71.                         break;
  72.                     case 6:
  73.                         System.out.println("Numero de nodos del arbol: "+arb.numNodos(arb.raiz));
  74.                         break;
  75.                     case 7:
  76.                         System.out.println("Cantidad de Nodos Hoja: "+arb.cantidadNodosHoja(arb.raiz));
  77.                         break;
  78.                     case 8:
  79.                         System.out.println("Nivel del Arbol "+(arb.retornarAltura()-1));
  80.                         break;
  81.                     case 9:
  82.                         System.out.println("Altura del Arbol "+arb.retornarAltura());
  83.                         break;
  84.                     case 10:
  85.                         System.out.println("Recorrido Descendente");
  86.                         arb.descendente(arb.raiz);
  87.                         break;
  88.                     case 11:
  89.                         break;
  90.                     default:
  91.                         System.out.println("Ingrese opcion correcta");
  92.                     }
  93.                 }catch(NumberFormatException a){
  94.                 System.out.println("Error "+a.getMessage());
  95.                 }
  96.         }while(opcion != 11);
  97.     }    
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement