Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package arbolbb;
- import java.util.Scanner;
- public class ArbolBB {
- public static void main(String[] args) {
- int opcion=0;
- int dato;
- Scanner sc = new Scanner(System.in);
- ArbolBinB arb = new ArbolBinB();
- do{
- try{
- System.out.println("");
- System.out.println("1. Agregar Nodo");
- System.out.println("2. Reocorrer el Arbol In Order");
- System.out.println("3. Reocorrer el Arbol Pre Order");
- System.out.println("4. Reocorrer el Arbol Pos Order");
- System.out.println("5. Buscar un Nodo en el Arbol");
- System.out.println("6. Numero de Nodos del Arbol");
- System.out.println("7. Numero de Nodos Hoja del Arbol");
- System.out.println("8. Nivel del Arbol");
- System.out.println("9. Altura del Arbol");
- System.out.println("10. Recorrido Descendente");
- System.out.println("11. Salir");
- System.out.print("Ingrese opcion ==> ");
- opcion = sc.nextInt();
- switch (opcion){
- case 1:
- System.out.println("Ingrese dato");
- dato = sc.nextInt();
- arb.agregarNodo(dato);
- break;
- case 2:
- if (!arb.estaVacio()) {
- arb.inOrder(arb.raiz);
- }else{
- System.out.println("El Arbol está vacio");
- }
- break;
- case 3:
- if (!arb.estaVacio()) {
- arb.preOrder(arb.raiz);
- }else{
- System.out.println("El Arbol está vacio");
- }
- break;
- case 4:
- if (!arb.estaVacio()) {
- arb.posOrder(arb.raiz);
- }else{
- System.out.println("El Arbol está vacio");
- }
- break;
- case 5:
- if (!arb.estaVacio()) {
- System.out.println("Ingrese valor a buscar en el Arbol:");
- NodoArbol busNod = arb.buscarNodo(sc.nextInt());
- if (busNod == null) {
- System.out.println("El valor no esta en el Arbol");
- }else{
- System.out.println("El valor "+busNod.Dato+" esta en el Arbol");
- }
- }else{
- System.out.println("El Arbol está vacio");
- }
- break;
- case 6:
- System.out.println("Numero de nodos del arbol: "+arb.numNodos(arb.raiz));
- break;
- case 7:
- System.out.println("Cantidad de Nodos Hoja: "+arb.cantidadNodosHoja(arb.raiz));
- break;
- case 8:
- System.out.println("Nivel del Arbol "+(arb.retornarAltura()-1));
- break;
- case 9:
- System.out.println("Altura del Arbol "+arb.retornarAltura());
- break;
- case 10:
- System.out.println("Recorrido Descendente");
- arb.descendente(arb.raiz);
- break;
- case 11:
- break;
- default:
- System.out.println("Ingrese opcion correcta");
- }
- }catch(NumberFormatException a){
- System.out.println("Error "+a.getMessage());
- }
- }while(opcion != 11);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement