Advertisement
s00rk

Principal

Dec 12th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. package Arboles;
  2. import java.util.*;
  3.  
  4. public class Principal extends Metodos
  5. {
  6.     static Scanner read = new Scanner(System.in);
  7.     public static void main(String[] args)
  8.     {
  9.         Random rand = new Random();
  10.         ABB A = new ABB();
  11.        
  12.         A.Raiz = A.CreaNodo(rand.nextInt(100));
  13.         for(int i = 0; i < 20; i++)
  14.             while(!A.InsertaABB(rand.nextInt(100), A.Raiz));
  15.        
  16.         int OP = -1;
  17.         do{
  18.             SOP("[1] Buscar numero en el arbol");
  19.             SOP("[2] Ver Si X es Padre de Y");
  20.             SOP("[3] Imprimir hijos de X");
  21.             SOP("[4] Imprimir todas los nodos hojas");
  22.             SOP("[5] Imprimir todos los nodos intermedios");
  23.             SOP("[6] Imprimir si X & Y son hermnos");
  24.             SOP("[7] Ver si X es abuelo de Y");
  25.             SOP("[8] Ver nivel de X");
  26.             SOP("[9] Imprimir Altura del Arbol");
  27.             SOP("[10] Eliminar Arbol Completo");
  28.             SOP("[11] Grado del Arbol");
  29.             SOP("[12] Total de Nodos");
  30.             SOP("[13] Total de Nodos del Lado Derecho");
  31.             SOP("[14] Total de Nodos del Lado Izquierdo");
  32.             SOP("[15] Checar si el Arbol esta Completo");
  33.            
  34.             OP = Leer("\nSelcciona una opcion:");
  35.            
  36.             switch(OP)
  37.             {
  38.             case 1:
  39.                 if(Metodo1(Leer("Ingresa Numero a buscar:"), A.Raiz))
  40.                     SOP("Existe!");
  41.                 else
  42.                     SOP("No Existe!");
  43.                 break;
  44.                
  45.             case 2:
  46.                 if(Metodo2(Leer("Ingresa X:"), Leer("Ingresa Y:"), A.Raiz))
  47.                     SOP("Si es Padre");
  48.                 else
  49.                     SOP("No es Padre!");
  50.                 break;
  51.                
  52.             case 3:
  53.                 Metodo3(Leer("Ingresa X:"), A.Raiz);
  54.                 break;
  55.                
  56.             case 4:
  57.                 Metodo4(A.Raiz);
  58.                 break;
  59.                
  60.             case 5:
  61.                 Metodo5(A.Raiz, A.Raiz.X);
  62.                 break;
  63.                
  64.             case 6:
  65.                 if(Metodo6(Leer("Ingresa X"), Leer("Ingresa Y:"), A.Raiz))
  66.                     SOP("Son Hermanos!");
  67.                 else
  68.                     SOP("No son Hermanos!");
  69.                 break;
  70.             case 7:
  71.                 if(Metodo7(Leer("Ingrese X"), Leer("Ingrese Y"), A.Raiz))
  72.                     SOP("Si es abuelo");
  73.                 else
  74.                     SOP("No es abuelo!");
  75.                 break;
  76.             case 8:
  77.                 Metodo8(Leer("Ingrese X"),1, A.Raiz);
  78.                 break;
  79.             case 9:
  80.                 SOP("Altura del Arbol: " + (Metodo9(A.Raiz)+1));
  81.                 break;
  82.             case 10:
  83.                 A.Raiz = Metodo10(A.Raiz);
  84.                 A.PreOrden(A.Raiz);
  85.                 break;
  86.             case 11:
  87.                 SOP("Grado del Arbol: " + Metodo11(A.Raiz));
  88.                 break;
  89.             case 12:
  90.                 SOP("Total de Nodos: " + Metodo12(A.Raiz));
  91.                 break;
  92.             case 13:
  93.                 SOP("Total de Nodos: " + Metodo13(A.Raiz));
  94.                 break;
  95.             case 14:
  96.                 SOP("Total de Nodos: " + Metodo14(A.Raiz));
  97.                 break;
  98.             case 15:
  99.                 if(Metodo15(A.Raiz))
  100.                     SOP("Esta Completa");
  101.                 else
  102.                     SOP("No esta Completa");
  103.                 break;
  104.             case 0:
  105.                 break;
  106.             default:
  107.                 SOP("Opcion Invalida!");   
  108.             }
  109.             try{
  110.             if(OP != 0)
  111.                 Thread.sleep(2000);
  112.             else
  113.                 Thread.sleep(9000);
  114.             }catch(InterruptedException e) {
  115.             }
  116.                
  117.         }while(OP != 0);
  118.        
  119.     }
  120.        
  121.     private static int Leer(String msj)
  122.     {
  123.         SOP(msj);
  124.         return read.nextInt();
  125.     }
  126.    
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement