Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Arboles;
- import java.util.*;
- public class Principal extends Metodos
- {
- static Scanner read = new Scanner(System.in);
- public static void main(String[] args)
- {
- Random rand = new Random();
- ABB A = new ABB();
- A.Raiz = A.CreaNodo(rand.nextInt(100));
- for(int i = 0; i < 20; i++)
- while(!A.InsertaABB(rand.nextInt(100), A.Raiz));
- int OP = -1;
- do{
- SOP("[1] Buscar numero en el arbol");
- SOP("[2] Ver Si X es Padre de Y");
- SOP("[3] Imprimir hijos de X");
- SOP("[4] Imprimir todas los nodos hojas");
- SOP("[5] Imprimir todos los nodos intermedios");
- SOP("[6] Imprimir si X & Y son hermnos");
- SOP("[7] Ver si X es abuelo de Y");
- SOP("[8] Ver nivel de X");
- SOP("[9] Imprimir Altura del Arbol");
- SOP("[10] Eliminar Arbol Completo");
- SOP("[11] Grado del Arbol");
- SOP("[12] Total de Nodos");
- SOP("[13] Total de Nodos del Lado Derecho");
- SOP("[14] Total de Nodos del Lado Izquierdo");
- SOP("[15] Checar si el Arbol esta Completo");
- OP = Leer("\nSelcciona una opcion:");
- switch(OP)
- {
- case 1:
- if(Metodo1(Leer("Ingresa Numero a buscar:"), A.Raiz))
- SOP("Existe!");
- else
- SOP("No Existe!");
- break;
- case 2:
- if(Metodo2(Leer("Ingresa X:"), Leer("Ingresa Y:"), A.Raiz))
- SOP("Si es Padre");
- else
- SOP("No es Padre!");
- break;
- case 3:
- Metodo3(Leer("Ingresa X:"), A.Raiz);
- break;
- case 4:
- Metodo4(A.Raiz);
- break;
- case 5:
- Metodo5(A.Raiz, A.Raiz.X);
- break;
- case 6:
- if(Metodo6(Leer("Ingresa X"), Leer("Ingresa Y:"), A.Raiz))
- SOP("Son Hermanos!");
- else
- SOP("No son Hermanos!");
- break;
- case 7:
- if(Metodo7(Leer("Ingrese X"), Leer("Ingrese Y"), A.Raiz))
- SOP("Si es abuelo");
- else
- SOP("No es abuelo!");
- break;
- case 8:
- Metodo8(Leer("Ingrese X"),1, A.Raiz);
- break;
- case 9:
- SOP("Altura del Arbol: " + (Metodo9(A.Raiz)+1));
- break;
- case 10:
- A.Raiz = Metodo10(A.Raiz);
- A.PreOrden(A.Raiz);
- break;
- case 11:
- SOP("Grado del Arbol: " + Metodo11(A.Raiz));
- break;
- case 12:
- SOP("Total de Nodos: " + Metodo12(A.Raiz));
- break;
- case 13:
- SOP("Total de Nodos: " + Metodo13(A.Raiz));
- break;
- case 14:
- SOP("Total de Nodos: " + Metodo14(A.Raiz));
- break;
- case 15:
- if(Metodo15(A.Raiz))
- SOP("Esta Completa");
- else
- SOP("No esta Completa");
- break;
- case 0:
- break;
- default:
- SOP("Opcion Invalida!");
- }
- try{
- if(OP != 0)
- Thread.sleep(2000);
- else
- Thread.sleep(9000);
- }catch(InterruptedException e) {
- }
- }while(OP != 0);
- }
- private static int Leer(String msj)
- {
- SOP(msj);
- return read.nextInt();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement