Roke98

Ejercicio1-Tp5-Unju

Nov 9th, 2022 (edited)
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. public class Ejercicio1 {
  2.  
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.         menu();
  6.     }
  7.    
  8.     public static void menu() {
  9.         BinaryTree<Character> a1 = new BinaryTree<Character>('B', new BinaryTree<Character>('A'), new BinaryTree<Character>('C'));
  10.         BinaryTree<Character> a2 = new BinaryTree<Character>('G', new BinaryTree<Character>('F'), null);
  11.         BinaryTree<Character> a3 = new BinaryTree<Character>('E', null, a2);
  12.         BinaryTree<Character> a = new BinaryTree<Character>('D',a1,a3);
  13.        
  14.         int opcion;
  15.         do {
  16.             System.out.println("Arbol:\n " + a.toString());
  17.             System.out.println("1 - Mostrar datos del arbol");
  18.             System.out.println("2 - Mostar Recorrido del arbol en ORDEN DESCENDENTE");
  19.             opcion = Helper.getPositiveInt("Ingrese una opcion");
  20.             switch(opcion) {
  21.             case 1:
  22.                 datosDeA(a);
  23.                 Helper.espera();
  24.                 break;
  25.             case 2:
  26.                 recorridoDeA(a);
  27.                 Helper.espera();
  28.                 break;
  29.             case 3:
  30.                 break;
  31.             default:
  32.                 System.out.println("Erro: opcion no valida");
  33.             }
  34.            
  35.         }while(opcion != 3);
  36.         System.out.println("Gracias :D");
  37.     }
  38.    
  39.     public static void datosDeA(BinaryTree<Character> arbol) {
  40.         System.out.println("DATOS DEL ARBOL");
  41.         System.out.println("****************************************");
  42.         System.out.println("El numero total de nodos es: " + arbol.NodeCount());
  43.         System.out.println("El numero de hojas es: " + arbol.LeafCount());
  44.         System.out.println("El numero de nodos internos es: " + arbol.InternalCount());
  45.         System.out.println("El nivel maximo del arbol es: " + arbol.MaxLevel());
  46.         System.out.println("La altura del arbol es: " + arbol.Height());
  47.         System.out.println("****************************************");
  48.     }
  49.    
  50.     public static void recorridoDeA(BinaryTree<Character> arbol) {
  51.         System.out.println("El orden descendente es:");
  52.         arbol.DescendingOrder();
  53.         System.out.println();
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment