Arboles Java
Arboles Java
3, clase ÁrbolBinario
package arbolBinario;
return valor;
}
}
EJEMPLO 13.7
EJEMPLO 13.11
import java.io.*;
import arbolBinarioOrdenado.*;
import arbolBinario.*;
}
public class ArbolEstudiante
{
public static void main(String [] a)
{
ArbolBinarioBusqueda ab = new ArbolBinarioBusqueda();
BufferedReader entrada = new BufferedReader(
new InputStreamReader(System.in));
Estudiante el;
int nm;
String nom;
try {
// Se crea el árbol de búsqueda
do{
System.out.print("Numero de matricula(0 -> Fin): ");
nm = Integer.parseInt(entrada.readLine());
if (nm > 0)
{
System.out.print("Nombre: ");
nom = entrada.readLine();
el = new Estudiante(nom, nm);
ab.insertar(el);
}
}while (nm != 0);
// Operaciones con el arbol
do {
System.out.print(" 1. Mostrar el árbol\n");
System.out.print(" 2. Eliminar un estudiante\n");
System.out.print(" 3. Salir\n ");
do
nm = Integer.parseInt(entrada.readLine());
while(nm < 1 || nm > 3);
if (nm == 1)
{
System.out.print("\n\tEstudiantes \n");
visualizar(ab.raizArbol());
}
else if (nm == 2)
{
int nmt;
System.out.print ("Matricula: ");
nmt = Integer.parseInt(entrada.readLine());
try {
ab.eliminar(new Estudiante(null,nmt));
}
catch (Exception e)
{
System.out.println(e);
}
}
}while (nm != 3);
}
catch (Exception er)
{
System.out.println("Error en el proceso del arbol: " + er);
}
}
EJERCICIO 13.7
EJERCICIO 13.11