Arbol Binario
* TAD ARBOL BINARIO CON TODOS SUS METODOS **
* **
* . **
* **
*PARA: ESTRUCTURAS DE DATOS 2. **
* **
**********++++++++++++++++++++++++++++++++++++++++++************/
import javax.swing.JOptionPane;
public class Arbin {
publicNodo raiz;
public int tam;
public Arbin(){
raiz = null;
tam = 0;
}
//consulta si es vacio
boolean esVacio(){
if(tam==0)
return true;
else
return false;
}//Insercion de un elemento en el arbol
public void ingresarNodo(int Elem){
if(raiz == null){
raiz = new Nodo (Elem);
tam++;
}
else{
raiz.insertarNodo (Elem);
tam++;
}
}//Preorden Recursivo del arbol
public void preorden (Nodo x){
if(x == null)
return;
else{
if (x.get_contenido()!=-1)
JOptionPane.showMessageDialog(null, x.get_contenido(),"ELEMENTOS ARBOL EN PREORDEN", JOptionPane.INFORMATION_MESSAGE);
preorden (x.get_izq());
preorden (x.get_der());
}
}
//PostOrden recursivo del arbol
public void postorden(Nodo x){
if(x == null)
return;
else{
postorden (x.get_izq());
postorden (x.get_der());
if (x.get_contenido()!=-1)
JOptionPane.showMessageDialog(null, x.get_contenido(),"ELEMENTOS ARBOL EN POSTORDEN", JOptionPane.INFORMATION_MESSAGE);
}
}
//Inorden Recursivo del arbol
public void inorden (Nodo x){
if(x == null)
return;
else{
inorden(x.get_izq());
if (x.get_contenido()!=-1)
JOptionPane.showMessageDialog(null, x.get_contenido(),
"ELEMENTOS ARBOL EN INORDEN", JOptionPane.INFORMATION_MESSAGE);
inorden (x.get_der());}
}
//Busca un elemento en el arbol
public boolean buscar (int m, Nodo x){
while (x != null && x.get_contenido() != m){
if(m > x.get_contenido())
return buscar (m,...
Regístrate para leer el documento completo.