Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Arboles;
- public class Metodos
- {
- public static void SOP(String msj)
- {
- System.out.println(msj);
- }
- public static boolean Metodo1(int C, pNodoArbol nodo)
- {
- if(nodo == null)
- return false;
- if(nodo.X == C)
- return true;
- if(C < nodo.X)
- return Metodo1(C, nodo.LigaIzq);
- else if(C > nodo.X)
- return Metodo1(C, nodo.LigaDer);
- return false;
- }
- public static boolean Metodo2(int X, int Y, pNodoArbol nodo)
- {
- if(nodo == null)
- return false;
- if(nodo.X == X)
- {
- if(nodo.LigaIzq != null && nodo.LigaIzq.X == Y)
- return true;
- else if(nodo.LigaDer != null && nodo.LigaDer.X == Y)
- return true;
- else
- return false;
- }
- if(X < nodo.X)
- return Metodo2(X, Y, nodo.LigaIzq);
- else if(X > nodo.X)
- return Metodo2(X, Y, nodo.LigaDer);
- return false;
- }
- public static void Metodo3(int X, pNodoArbol nodo)
- {
- if(nodo == null)
- return;
- if(nodo.X == X)
- {
- if(nodo.LigaIzq != null)
- SOP(nodo.LigaIzq.X+"");
- if(nodo.LigaDer != null)
- SOP(nodo.LigaDer.X+"");
- }
- if(X < nodo.X)
- Metodo3(X, nodo.LigaIzq);
- else if(X > nodo.X)
- Metodo3(X, nodo.LigaDer);
- }
- public static void Metodo4(pNodoArbol nodo)
- {
- if(nodo == null)
- return;
- Metodo4(nodo.LigaIzq);
- if(nodo.LigaIzq == null && nodo.LigaDer == null)
- SOP(nodo.X+"");
- Metodo4(nodo.LigaDer);
- }
- public static void Metodo5(pNodoArbol nodo, int Raiz)
- {
- if(nodo == null)
- return;
- Metodo5(nodo.LigaIzq, Raiz);
- if((nodo.LigaIzq != null || nodo.LigaDer != null) && nodo.X != Raiz)
- SOP(nodo.X+"");
- Metodo5(nodo.LigaDer, Raiz);
- }
- public static boolean Metodo6(int X, int Y, pNodoArbol nodo)
- {
- if(nodo.LigaDer == null && nodo.LigaIzq == null)
- return false;
- if(nodo.LigaIzq.X == X || nodo.LigaDer.X == X)
- {
- if(nodo.LigaDer.X == Y || nodo.LigaIzq.X == Y)
- return true;
- }
- if(X < nodo.X)
- return Metodo6(X, Y, nodo.LigaIzq);
- else if(X > nodo.X)
- return Metodo6(X, Y, nodo.LigaDer);
- return false;
- }
- public static boolean Metodo7(int X, int Y, pNodoArbol nodo)
- {
- if(nodo == null)
- return false;
- if(nodo.X == X)
- {
- pNodoArbol aux;
- if(nodo.LigaIzq != null)
- {
- aux = nodo.LigaIzq;
- if(aux.LigaIzq != null && aux.LigaIzq.X == Y)
- return true;
- else if(aux.LigaDer!= null && aux.LigaDer.X == Y)
- return true;
- }else if(nodo.LigaDer != null){
- aux = nodo.LigaDer;
- if(aux.LigaDer != null && aux.LigaDer.X == Y)
- return true;
- else if(aux.LigaIzq != null && aux.LigaIzq.X == Y)
- return true;
- }
- return false;
- }
- if(X < nodo.X)
- return Metodo7(X, Y, nodo.LigaIzq);
- else if(X > nodo.X)
- return Metodo7(X, Y, nodo.LigaDer);
- return false;
- }
- public static void Metodo8(int X, int nivel, pNodoArbol nodo)
- {
- if(!Metodo1(X, nodo))
- {
- SOP("\nNo se encuentra!");
- return;
- }
- if(nodo.X == X)
- {
- SOP("\nEsta en el nivel: " + nivel);
- return;
- }
- if(X < nodo.X)
- Metodo8(X, nivel+1, nodo.LigaIzq);
- else if(X > nodo.X)
- Metodo8(X, nivel+1, nodo.LigaDer);
- }
- public static int Metodo9(pNodoArbol nodo)
- {
- if (nodo == null)
- return -1;
- return 1 + Math.max(Metodo9(nodo.LigaIzq), Metodo9(nodo.LigaDer));
- }
- public static pNodoArbol Metodo10(pNodoArbol nodo)
- {
- if(nodo != null)
- {
- Metodo10(nodo.LigaIzq);
- Metodo10(nodo.LigaDer);
- nodo = null;
- }
- return nodo;
- }
- public static int Metodo11(pNodoArbol nodo,int i)
- {
- }
- public static int Metodo12(pNodoArbol nodo)
- {
- if(nodo == null)
- return 0;
- else
- return (1 + Metodo12(nodo.LigaIzq) + Metodo12(nodo.LigaDer));
- }
- public static int Metodo13(pNodoArbol nodo)
- {
- int resp = 0;
- if(nodo != null && nodo.LigaDer != null)
- resp = Metodo12(nodo.LigaDer);
- return resp;
- }
- public static int Metodo14(pNodoArbol nodo)
- {
- int resp = 0;
- if(nodo != null && nodo.LigaIzq != null)
- resp = Metodo12(nodo.LigaIzq);
- return resp;
- }
- public static boolean Metodo15(pNodoArbol nodo)
- {
- return (Metodo13(nodo)==Metodo14(nodo)) ? true : false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement