Started work on trees.

This commit is contained in:
Chris Cromer
2016-07-04 11:38:26 -04:00
parent a8b2b34be4
commit b888744104
45 changed files with 754 additions and 260 deletions

View File

@@ -0,0 +1,125 @@
package cl.cromer.estructuras;
public class Arbol {
private ArbolNodo arbol;
private int size;
private int altura;
private int ancho;
public enum PrimerLado {
IZQUERDA,
DERECHA
}
public Arbol() {
this.arbol = null;
this.altura = 0;
this.ancho = 0;
}
public boolean insertar(int valor) {
if (this.arbol == null) {
arbol = new ArbolNodo(valor);
arbol.setY(1);
arbol.setX(1);
ancho = 1;
altura = 1;
return true;
}
else {
PrimerLado primerLado = null;
ArbolNodo nuevo = new ArbolNodo(valor);
ArbolNodo actual = arbol;
ArbolNodo padre;
while (true) {
padre = actual;
if (valor == actual.getValor()) {
// Ya existe.
return false;
}
else if (valor < actual.getValor()) {
// Izquerda
if (primerLado == null) {
primerLado = PrimerLado.IZQUERDA;
nuevo.setX(1);
}
else {
nuevo.setX(nuevo.getX() + 1);
}
nuevo.setY(nuevo.getY() + 1);
actual = actual.getIzquerda();
if (actual == null) {
padre.setIzquerda(nuevo);
size++;
if (primerLado == PrimerLado.IZQUERDA) {
ancho++;
}
setAltura(getAlturaRecursivo(arbol));
return true;
}
}
else {
// Derecha
if (primerLado == null) {
primerLado = PrimerLado.DERECHA;
nuevo.setX(1);
}
else {
nuevo.setX(nuevo.getX() + 1);
}
nuevo.setY(nuevo.getY() + 1);
actual = actual.getDerecha();
if (actual == null) {
padre.setDerecha(nuevo);
size++;
if (primerLado == PrimerLado.DERECHA) {
ancho++;
}
setAltura(getAlturaRecursivo(arbol));
return true;
}
}
}
}
}
public ArbolNodo getArbol() {
return arbol;
}
public int size() {
return size;
}
public int getAltura() {
return altura;
}
public void setAltura(int altura) {
this.altura = altura;
}
public int getAncho() {
return ancho;
}
public void setAncho(int ancho) {
this.ancho = ancho;
}
public int getAlturaRecursivo(ArbolNodo nodo) {
if (nodo == null) {
return 0;
}
else {
int alturaIzquerda = getAlturaRecursivo(nodo.getIzquerda());
int alturaDercha = getAlturaRecursivo(nodo.getDerecha());
if (alturaIzquerda > alturaDercha) {
return (alturaIzquerda + 1);
}
else {
return (alturaDercha + 1);
}
}
}
}

View File

@@ -0,0 +1,205 @@
package cl.cromer.estructuras;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import java.net.URL;
import java.util.Queue;
import java.util.ResourceBundle;
import java.util.Scanner;
import java.util.Stack;
import java.util.logging.Level;
/**
* Esta clase es para controlar todos la interfaz de Arbol.
*
* @author Chris Cromer
*/
public class ArbolController implements Initializable {
/**
* La caja para ingresar textos.
*/
@FXML
private TextFieldLimited valorArbol;
/**
* Donde poner el contenido de array.
*/
@FXML
private GridPane contenidoArbol;
/**
* Donde va el codigo a mostrar a la pantalla.
*/
@FXML
private Text codigoArbol;
/**
* La escena donde está cosas graficas.
*/
private Scene scene;
/**
* Donde está guardado los idiomas.
*/
private ResourceBundle resourceBundle;
/**
* El arbol usado en la aplicación.
*/
private Arbol arbol;
/**
* Grafico rectangulos.
*/
private Grafico grafico;
/**
* Inicializar todos los datos y dibujar las graficas.
*
* @param location URL: El URL de fxml en uso.
* @param resourceBundle ResourceBundle: Tiene datos de idioma.
*/
@Override
public void initialize(URL location, ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
arbol = null;
scene = null;
// TODO: Remove this
arbol = new Arbol();
arbol.insertar(5);
arbol.insertar(4);
arbol.insertar(3);
arbol.insertar(2);
arbol.insertar(1);
}
/**
* Insertar un valor al array y mostrar el codigo en la pantalla.
*/
@FXML
protected void botonInsertar() {
if (scene == null) {
initializeArbol();
}
// Mostrar el codigo
/*String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/insertar")).useDelimiter("\\Z").next();
codigoArray.setText(codigoTexto);*/
/*if (valorArbol.getText() != null && ! valorArbol.getText().trim().equals("")) {
try {
boolean exito = arbol.insertar(Integer.valueOf(valorArbol.getText()));
if (exito) {
valorArbol.setText("");
generarGrafico();
}
else {
Main.mostrarError(resourceBundle.getString("arbolValorExiste"), resourceBundle);
}
}
catch (NumberFormatException exception) {
// El error no es fatal, sigue
Logs.log(Level.WARNING, "No es tipo int.");
Main.mostrarError(resourceBundle.getString("arbolNoValor"), resourceBundle);
}
}
else {
Main.mostrarError(resourceBundle.getString("arbolNoValor"), resourceBundle);
}*/
generarGrafico();
}
/**
* Crear un arbol nuevo.
*/
private void initializeArbol() {
scene = contenidoArbol.getScene();
// TODO: remove this
contenidoArbol.setGridLinesVisible(true);
grafico = new Grafico(scene);
//this.arbol = new Arbol();
ArbolTipos arbolTipos = (ArbolTipos) scene.getUserData();
}
/**
* Poner los valores en el grafico.
*/
private void generarGrafico() {
grafico.removerDestacar();
Node node = contenidoArbol.getChildren().get(0);
contenidoArbol.getChildren().clear();
contenidoArbol.getChildren().add(0, node);
Text text;
int ancho = arbol.getAncho();
if (ancho % 2 == 0) {
ancho++;
}
for (int i = 0; i < arbol.getAltura(); i++) {
contenidoArbol.addRow(i);
for (int j = 0; j < ancho; j++) {
contenidoArbol.addColumn(j);
text = new Text();
text.setText(" ");
text.setId(j + "_" + i);
contenidoArbol.add(text, j, i);
}
}
int medio = ancho / 2;
ArbolNodo tempArbol = this.arbol.getArbol();
Stack globalStack = new Stack();
globalStack.push(tempArbol);
boolean filaVacio = false;
int x = medio;
int y = 0;
while (!filaVacio) {
Stack localStack = new Stack();
filaVacio = true;
text = new Text();
text.setText(" ");
text.setId(x + "_" + y);
contenidoArbol.add(text, x, y);
while (!globalStack.isEmpty()) {
ArbolNodo temp = (ArbolNodo) globalStack.pop();
if (temp != null) {
//System.out.print(temp.iData);
text = new Text();
text.setText(String.valueOf(temp.getValor()));
text.setId(x + "_" + y);
contenidoArbol.add(text, x, y);
localStack.push(temp.getIzquerda());
localStack.push(temp.getDerecha());
if(temp.getIzquerda() != null ||
temp.getDerecha() != null)
filaVacio = false;
}
else {
System.out.print("--");
localStack.push(null);
localStack.push(null);
}
x++;
}
y++;
x = 0;
// Next level
while(!localStack.isEmpty())
globalStack.push( localStack.pop() );
}
}
}

View File

@@ -0,0 +1,73 @@
package cl.cromer.estructuras;
final public class ArbolNodo {
private ArbolNodo izquerda;
private ArbolNodo derecha;
private int valor;
private int y;
private int x;
private Desde desde;
public ArbolNodo(int valor) {
this.izquerda = null;
this.derecha = null;
this.valor = valor;
this.y = 0;
this.x = 0;
this.desde = Desde.RAIZ;
}
public ArbolNodo getIzquerda() {
return izquerda;
}
public void setIzquerda(ArbolNodo izquerda) {
this.izquerda = izquerda;
}
public ArbolNodo getDerecha() {
return derecha;
}
public void setDerecha(ArbolNodo derecha) {
this.derecha = derecha;
}
public int getValor() {
return valor;
}
public int getY() {
return y;
}
public void setY(int y) {
if (y >= 0) {
this.y = y;
}
}
public int getX() {
return x;
}
public void setX(int x) {
if (x >= 0) {
this.x = x;
}
}
public Desde getDesde() {
return desde;
}
public void setDesde(Desde desde) {
this.desde = desde;
}
public enum Desde {
RAIZ,
IQUERDA,
DERECHA
}
}

View File

@@ -28,6 +28,11 @@ public class Colores {
*/
private Color fondo;
/**
* El color de border actual.
*/
private Color border;
/**
* Inicializar el primer color.
*/
@@ -44,36 +49,43 @@ public class Colores {
color = 2;
texto = Color.WHITE;
fondo = Color.RED;
border = Color.BLACK;
break;
case 2:
color = 3;
texto = Color.BLACK;
fondo = Color.WHITE;
border = Color.BLACK;
break;
case 3:
color = 4;
texto = Color.BLACK;
fondo = Color.PINK;
border = Color.BLACK;
break;
case 4:
color = 5;
texto = Color.BLACK;
fondo = Color.YELLOW;
border = Color.BLACK;
break;
case 5:
color = 6;
texto = Color.BLACK;
fondo = Color.GREEN;
border = Color.BLACK;
break;
case 6:
color = 7;
texto = Color.BLACK;
fondo = Color.ORANGE;
border = Color.BLACK;
break;
default:
color = 1;
texto = Color.WHITE;
fondo = Color.BLUE;
border = Color.BLACK;
}
}
@@ -94,4 +106,13 @@ public class Colores {
public Color getFondo() {
return fondo;
}
/**
* Devolver el color del border actual.
*
* @return Color: Color del border.
*/
public Color getBorder() {
return border;
}
}

View File

@@ -172,7 +172,7 @@ public class Grafico {
rectangle.setHeight(40);
rectangle.setWidth(40);
rectangle.setFill(colores.getFondo());
rectangle.setStroke(Color.BLACK);
rectangle.setStroke(colores.getBorder());
rectangle.setId("caja_" + label);
Text text = new Text();
text.setId("texto_" + label);
@@ -197,7 +197,7 @@ public class Grafico {
rectangle.setHeight(40);
rectangle.setWidth(40);
rectangle.setFill(colores.getFondo());
rectangle.setStroke(Color.BLACK);
rectangle.setStroke(colores.getBorder());
rectangle.setId("caja_" + label);
Text text = new Text();
text.setId("texto_" + label);
@@ -209,6 +209,22 @@ public class Grafico {
return stackPane;
}
public static StackPane crearCirculo(Colores colores, String label) {
Circle circle = new Circle();
circle.setRadius(20);
circle.setFill(colores.getFondo());
circle.setStroke(colores.getBorder());
circle.setId("circulo_" + label);
Text text = new Text();
text.setId("texto_" + label);
text.setStroke(colores.getTexto());
StackPane stackPane = new StackPane();
stackPane.getChildren().addAll(circle, text);
return stackPane;
}
/**
* Crear 3 rectangulos.
*
@@ -222,7 +238,7 @@ public class Grafico {
rectangle.setHeight(40);
rectangle.setWidth(40);
rectangle.setFill(colores.getFondo());
rectangle.setStroke(Color.BLACK);
rectangle.setStroke(colores.getBorder());
rectangle.setId("indice_caja_" + label);
Text text = new Text();
text.setId("indice_texto_" + label);
@@ -235,7 +251,7 @@ public class Grafico {
rectangle.setHeight(40);
rectangle.setWidth(120);
rectangle.setFill(colores.getFondo());
rectangle.setStroke(Color.BLACK);
rectangle.setStroke(colores.getBorder());
rectangle.setId("llave_caja_" + label);
text = new Text();
text.setId("llave_texto_" + label);
@@ -248,7 +264,7 @@ public class Grafico {
rectangle.setHeight(40);
rectangle.setWidth(40);
rectangle.setFill(colores.getFondo());
rectangle.setStroke(Color.BLACK);
rectangle.setStroke(colores.getBorder());
rectangle.setId("valor_caja_" + label);
text = new Text();
text.setId("valor_texto_" + label);

View File

@@ -1,11 +1,11 @@
package cl.cromer.estructuras;
/**
* Esta interfaz es para los 2 tipos de enlace, {@link EnlaceNormal} y {@link EnlaceCircular}.
* Esta interfaz es para los 2 tipos de enlace, {@link ListaEnlaceNormal} y {@link ListaEnlaceCircular}.
*
* @author Chris Cromer
*/
interface Enlace {
interface ListaEnlace {
/**
* Devolver la llave.
*

View File

@@ -5,7 +5,7 @@ package cl.cromer.estructuras;
*
* @author Chris Cromer
*/
final public class EnlaceCircular implements Enlace {
final public class ListaEnlaceCircular implements ListaEnlace {
/**
* La llave.
*/
@@ -14,12 +14,12 @@ final public class EnlaceCircular implements Enlace {
/**
* El siguiente enlace.
*/
private EnlaceCircular siguiente;
private ListaEnlaceCircular siguiente;
/**
* Incializar.
*/
public EnlaceCircular() {
public ListaEnlaceCircular() {
siguiente = null;
}
@@ -44,34 +44,34 @@ final public class EnlaceCircular implements Enlace {
/**
* Devolver el siguiente enlace.
*
* @return EnlaceCircular: El enlace a devolver.
* @return ListaEnlaceCircular: El enlace a devolver.
*/
public EnlaceCircular getSiguiente() {
public ListaEnlaceCircular getSiguiente() {
return siguiente;
}
/**
* Cambiar el siguiente enlace.
*
* @param siguiente Object: El siguiente enlace nuevo de tipo {@link EnlaceCircular}.
* @param siguiente Object: El siguiente enlace nuevo de tipo {@link ListaEnlaceCircular}.
*/
public void setSiguiente(Object siguiente) {
this.siguiente = (EnlaceCircular) siguiente;
this.siguiente = (ListaEnlaceCircular) siguiente;
}
/**
* Devolver el enlace previo.
*
* @return EnlaceCircular: El enlace previo.
* @return ListaEnlaceCircular: El enlace previo.
*/
public EnlaceCircular getPrevio() {
public ListaEnlaceCircular getPrevio() {
return null;
}
/**
* Dummy metodo para usar interface {@link Enlace}
* Dummy metodo para usar interface {@link ListaEnlace}
*
* @param previo Object: El enlace previo nuevo de tipo {@link EnlaceCircular}.
* @param previo Object: El enlace previo nuevo de tipo {@link ListaEnlaceCircular}.
*/
public void setPrevio(Object previo) {
}

View File

@@ -5,7 +5,7 @@ package cl.cromer.estructuras;
*
* @author Chris Cromer
*/
final public class EnlaceNormal implements Enlace {
final public class ListaEnlaceNormal implements ListaEnlace {
/**
* La llave.
*/
@@ -14,17 +14,17 @@ final public class EnlaceNormal implements Enlace {
/**
* El siguiente enlace.
*/
private EnlaceNormal siguiente;
private ListaEnlaceNormal siguiente;
/**
* El enlace previo por doble enlazada.
*/
private EnlaceNormal previo;
private ListaEnlaceNormal previo;
/**
* Incializar.
*/
public EnlaceNormal() {
public ListaEnlaceNormal() {
siguiente = null;
previo = null;
}
@@ -50,36 +50,36 @@ final public class EnlaceNormal implements Enlace {
/**
* Devolver el siguiente enlace.
*
* @return EnlaceNormal: El enlace a devolver.
* @return ListaEnlaceNormal: El enlace a devolver.
*/
public EnlaceNormal getSiguiente() {
public ListaEnlaceNormal getSiguiente() {
return siguiente;
}
/**
* Cambiar el siguiente enlace.
*
* @param siguiente Object: El siguiente enlace nuevo de tipo {@link EnlaceNormal}.
* @param siguiente Object: El siguiente enlace nuevo de tipo {@link ListaEnlaceNormal}.
*/
public void setSiguiente(Object siguiente) {
this.siguiente = (EnlaceNormal) siguiente;
this.siguiente = (ListaEnlaceNormal) siguiente;
}
/**
* Devolver el enlace previo.
*
* @return EnlaceNormal: El enlace previo.
* @return ListaEnlaceNormal: El enlace previo.
*/
public EnlaceNormal getPrevio() {
public ListaEnlaceNormal getPrevio() {
return previo;
}
/**
* Cambiar el previo enlace.
*
* @param previo Object: El enlace previo nuevo de tipo {@link EnlaceNormal}.
* @param previo Object: El enlace previo nuevo de tipo {@link ListaEnlaceNormal}.
*/
public void setPrevio(Object previo) {
this.previo = (EnlaceNormal) previo;
this.previo = (ListaEnlaceNormal) previo;
}
}

View File

@@ -9,7 +9,7 @@ final public class ListaEnlazada {
/**
* El enlace principal de la lista.
*/
private Enlace lista;
private ListaEnlace lista;
/**
* La cantidad de enlaces que están en la lista.
@@ -56,7 +56,7 @@ final public class ListaEnlazada {
public boolean insertar(int llave) {
if (buscar(llave) == null) {
// Crear una enlace y agregarla a la lista
Enlace nuevo = new EnlaceNormal();
ListaEnlace nuevo = new ListaEnlaceNormal();
nuevo.setLlave(llave);
nuevo.setSiguiente(lista);
if (lista != null) {
@@ -82,14 +82,14 @@ final public class ListaEnlazada {
public boolean eliminar(int llave) {
if (lista != null) {
// La lista no es vacia
Enlace lista = this.lista;
Enlace previo = lista;
ListaEnlace lista = this.lista;
ListaEnlace previo = lista;
while (lista.getLlave() != llave) {
// Buscar hasta la llave es encontraddo
if (lista.getSiguiente() != null) {
// Buscar en la siguiente enlace
previo = lista;
lista = (Enlace) lista.getSiguiente();
lista = (ListaEnlace) lista.getSiguiente();
}
else {
// No se encuentra
@@ -99,7 +99,7 @@ final public class ListaEnlazada {
// Se encontró
if (lista == this.lista) {
// Si es la primera enlace, cambiarla al siguiente enlace
this.lista = (Enlace) this.lista.getSiguiente();
this.lista = (ListaEnlace) this.lista.getSiguiente();
if (this.lista.getPrevio() != null) {
this.lista.setPrevio(null);
}
@@ -122,17 +122,17 @@ final public class ListaEnlazada {
*
* @param llave int: La llave a buscar.
*
* @return Enlace: El enlace que contiene la llave buscada.
* @return ListaEnlace: El enlace que contiene la llave buscada.
*/
public Enlace buscar(int llave) {
public ListaEnlace buscar(int llave) {
if (this.lista != null) {
// La lista no es vacia
Enlace lista = this.lista;
ListaEnlace lista = this.lista;
while (lista.getLlave() != llave) {
// Buscar hasta la llave es encontrado
if (lista.getSiguiente() != null) {
// Buscar en la siguiente enlace
lista = (Enlace) lista.getSiguiente();
lista = (ListaEnlace) lista.getSiguiente();
}
else {
// No se encuentra
@@ -153,14 +153,14 @@ final public class ListaEnlazada {
*
* @param indice int: El indice que desea ver.
*
* @return Enlace: El enlace a devolver.
* @return ListaEnlace: El enlace a devolver.
*/
public Enlace getIndice(int indice) {
public ListaEnlace getIndice(int indice) {
if (lista != null && indice >= 0 && indice < size()) {
int i = size();
Enlace lista = this.lista;
ListaEnlace lista = this.lista;
while (i > indice + 1) {
lista = (Enlace) lista.getSiguiente();
lista = (ListaEnlace) lista.getSiguiente();
i--;
}
return lista;

View File

@@ -9,12 +9,12 @@ final public class ListaEnlazadaCircular {
/**
* El primer enlace.
*/
private Enlace primer;
private ListaEnlace primer;
/**
* El ultimo enlace.
*/
private Enlace ultimo;
private ListaEnlace ultimo;
/**
* La cantidad de enlaces que hay.
@@ -61,16 +61,16 @@ final public class ListaEnlazadaCircular {
*/
public boolean insertar(int llave) {
if (buscar(llave) == null) {
// Crear una enlace y agregarla a la lista
Enlace enlace = new EnlaceCircular();
// Crear una listaEnlace y agregarla a la lista
ListaEnlace listaEnlace = new ListaEnlaceCircular();
if (primer == null) {
ultimo = enlace;
ultimo = listaEnlace;
}
enlace.setLlave(llave);
enlace.setSiguiente(primer);
primer = enlace;
listaEnlace.setLlave(llave);
listaEnlace.setSiguiente(primer);
primer = listaEnlace;
ultimo.setSiguiente(primer);
size++;
@@ -92,15 +92,15 @@ final public class ListaEnlazadaCircular {
public boolean eliminar(int llave) {
if (primer != null) {
// La lista no es vacia
Enlace lista = this.primer;
Enlace previo = lista;
ListaEnlace lista = this.primer;
ListaEnlace previo = lista;
int i = 0;
while (lista.getLlave() != llave && i < size()) {
// Buscar hasta la llave es encontraddo
if (lista.getSiguiente() != null) {
// Buscar en la siguiente enlace
previo = lista;
lista = (Enlace) lista.getSiguiente();
lista = (ListaEnlace) lista.getSiguiente();
}
i++;
}
@@ -113,7 +113,7 @@ final public class ListaEnlazadaCircular {
// Se encontró
if (lista == this.primer) {
// Si es la primera enlace, cambiarla al sigueinte enlace
this.primer = (Enlace) this.primer.getSiguiente();
this.primer = (ListaEnlace) this.primer.getSiguiente();
}
else {
// Sino cortar esta enlace de la lista
@@ -133,16 +133,16 @@ final public class ListaEnlazadaCircular {
*
* @param llave int: La llave a buscar.
*
* @return Enlace: El enlace que contiene la llave.
* @return ListaEnlace: El enlace que contiene la llave.
*/
public Enlace buscar(int llave) {
public ListaEnlace buscar(int llave) {
if (this.primer != null) {
// La lista no es vacia
Enlace lista = this.primer;
ListaEnlace lista = this.primer;
int i = 0;
while (lista.getLlave() != llave && i < size()) {
// Buscar en la sigenute enlace hasta el final.
lista = (Enlace) lista.getSiguiente();
lista = (ListaEnlace) lista.getSiguiente();
i++;
}
if (lista.getLlave() == llave) {
@@ -174,14 +174,14 @@ final public class ListaEnlazadaCircular {
*
* @param indice int: El indice que desea ver.
*
* @return Enlace: El enlace a devolver.
* @return ListaEnlace: El enlace a devolver.
*/
public Enlace getIndice(int indice) {
public ListaEnlace getIndice(int indice) {
if (primer != null && indice >= 0 && indice < size()) {
int i = size();
Enlace lista = this.primer;
ListaEnlace lista = this.primer;
while (i > indice + 1) {
lista = (Enlace) lista.getSiguiente();
lista = (ListaEnlace) lista.getSiguiente();
i--;
}
return lista;

View File

@@ -242,18 +242,18 @@ public class ListaEnlazdaController implements Initializable {
try {
if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) {
Enlace enlace;
ListaEnlace listaEnlace;
if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
enlace = listaEnlazada.buscar(Integer.valueOf(valorLista.getText()));
listaEnlace = listaEnlazada.buscar(Integer.valueOf(valorLista.getText()));
}
else {
enlace = listaEnlazadaCircular.buscar(Integer.valueOf(valorLista.getText()));
listaEnlace = listaEnlazadaCircular.buscar(Integer.valueOf(valorLista.getText()));
}
if (enlace != null) {
if (listaEnlace != null) {
generarGrafico();
grafico = new Grafico(scene);
grafico.destacar("#caja_" + enlace.getLlave(), Grafico.RECTANGULO);
grafico.destacar("#texto_" + enlace.getLlave(), Grafico.TEXTO);
grafico.destacar("#caja_" + listaEnlace.getLlave(), Grafico.RECTANGULO);
grafico.destacar("#texto_" + listaEnlace.getLlave(), Grafico.TEXTO);
}
else {
Main.mostrarError(resourceBundle.getString("listaNoEsta"), resourceBundle);
@@ -309,16 +309,16 @@ public class ListaEnlazdaController implements Initializable {
if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
for (int i = 0; i < listaEnlazada.size(); i++) {
Enlace enlace = listaEnlazada.getIndice(i);
ListaEnlace listaEnlace = listaEnlazada.getIndice(i);
if (listaEnlazada.getTipo() == ListaEnlazadaTipos.SIMPLE) {
dibujarSimple(enlace, false);
dibujarSimple(listaEnlace, false);
}
else if (listaEnlazada.getTipo() == ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA) {
if (i != listaEnlazada.size() - 1) {
dibujarDoble(enlace, (i == 0));
dibujarDoble(listaEnlace, (i == 0));
}
else {
dibujarSimple(enlace, false);
dibujarSimple(listaEnlace, false);
}
}
colores.siguinteColor();
@@ -326,8 +326,8 @@ public class ListaEnlazdaController implements Initializable {
}
else {
for (int i = 0; i < listaEnlazadaCircular.size(); i++) {
Enlace enlace = listaEnlazadaCircular.getIndice(i);
dibujarSimple(enlace, (i == listaEnlazadaCircular.size() - 1));
ListaEnlace listaEnlace = listaEnlazadaCircular.getIndice(i);
dibujarSimple(listaEnlace, (i == listaEnlazadaCircular.size() - 1));
colores.siguinteColor();
}
if (listaEnlazadaCircular.size() > 0) {
@@ -353,12 +353,12 @@ public class ListaEnlazdaController implements Initializable {
/**
* Dibujarlo con una flecha.
*
* @param enlace Enlace: El enlace que tiene la llave y valor.
* @param listaEnlace ListaEnlace: El listaEnlace que tiene la llave y valor.
* @param sinFlecha boolean: Verdad si necesita dibujar una flecha.
*/
private void dibujarSimple(Enlace enlace, boolean sinFlecha) {
private void dibujarSimple(ListaEnlace listaEnlace, boolean sinFlecha) {
contenidoLista.getChildren().addAll(
Grafico.crearCaja(colores, String.valueOf(enlace.getLlave()), String.valueOf(enlace.getLlave()))
Grafico.crearCaja(colores, String.valueOf(listaEnlace.getLlave()), String.valueOf(listaEnlace.getLlave()))
);
if (! sinFlecha) {
contenidoLista.getChildren().addAll(
@@ -371,10 +371,10 @@ public class ListaEnlazdaController implements Initializable {
/**
* Dibujarlo con dos flechas.
*
* @param enlace Enlace: El enlace que tiene la llave y valor.
* @param listaEnlace ListaEnlace: El listaEnlace que tiene la llave y valor.
* @param primer boolean: Verdad si es el primer elemento de la lista.
*/
private void dibujarDoble(Enlace enlace, boolean primer) {
private void dibujarDoble(ListaEnlace listaEnlace, boolean primer) {
if (primer) {
contenidoLista.getChildren().addAll(
Grafico.crearFlechaArriba(),
@@ -382,7 +382,7 @@ public class ListaEnlazdaController implements Initializable {
);
}
contenidoLista.getChildren().addAll(
Grafico.crearCaja(colores, String.valueOf(enlace.getLlave()), String.valueOf(enlace.getLlave())),
Grafico.crearCaja(colores, String.valueOf(listaEnlace.getLlave()), String.valueOf(listaEnlace.getLlave())),
Grafico.crearFlechaArriba(),
Grafico.crearLineaVertical(),
Grafico.crearFlechaAbajo()

View File

@@ -28,7 +28,7 @@ public class Main extends Application {
/**
* Estado de depuración.
*/
static final public boolean DEBUG = false;
static final public boolean DEBUG = true;
/**
* Crear el stage y la scene para la aplicación grafica.
@@ -50,6 +50,7 @@ public class Main extends Application {
catch (IOException exception) {
// Este error es fatal, hay que cerrar la aplicación.
Logs.log(Level.SEVERE, "No se pudo abrir el archivo de fxml.");
Logs.log(Level.SEVERE, exception.getMessage());
stage.close();
}

View File

@@ -213,6 +213,20 @@ public class MenuController extends VBox implements Initializable {
);
}
/**
* Click en Arbol General.
*/
@FXML
protected void menuArbolGeneral() {
ArbolTipos arbolTipos = new ArbolTipos(ArbolTipos.GENERAL);
loadStage(
resourceBundle.getString("tituloCola"),
"/cl/cromer/estructuras/fxml/arbol.fxml",
"/cl/cromer/estructuras/css/main.css",
arbolTipos
);
}
/**
* Click en Hash Table.
*/
@@ -344,6 +358,7 @@ public class MenuController extends VBox implements Initializable {
catch (IOException exception) {
// Este error es fatal, hay que cerrar la aplicación.
Logs.log(Level.SEVERE, "No se pudo abrir el archivo de fxml.");
Logs.log(Level.SEVERE, exception.getMessage());
stage.close();
}
@@ -360,6 +375,7 @@ public class MenuController extends VBox implements Initializable {
catch (IOException exception) {
// Este error es fatal, hay que cerrar la aplicación.
Logs.log(Level.SEVERE, "No se pudo abrir el archivo de fxml.");
Logs.log(Level.SEVERE, exception.getMessage());
stage.close();
}
}

View File

@@ -86,7 +86,10 @@ pilaNoValor=Please input a numeric value.
colaLlena=Value not inserted because the queue is full.
colaVacia=The queue is empty.
colaNoValor=Please input a numeric value.
tablaHashLleno=Key not inserted because hash table is full.
arbolValorExiste=Value already exists.
arbolNoEsta=Value does not exist.
arbolNoValor=Please input a numeric value.
tablaHashLleno=Key not inserted because the hash table is full.
tablaHashLlaveExiste=Key already exists.
tablaHashNoEsta=Key does not exist.
tablaHashNoLlave=Please input a key and a numeric value.

View File

@@ -85,6 +85,9 @@ pilaNoValor=Ingresar un valor num\u00E9rico por favor.
colaLlena=El valor no fue insertado porque la cola est\u00E1 llena.
colaVacia=La cola est\u00E1 vac\u00EDa.
colaNoValor=Ingresar un valor num\u00E9rico por favor.
arbolValorExiste=El valor ya existe.
arbolNoEsta=El valor no existe.
arbolNoValor=Ingresar un valor num\u00E9rico por favor.
tablaHashLleno=La llave no fue insertado porque la tabla hash est\u00E1 lleno.
tablaHashLlaveExiste=La llave ya existe.
tablaHashNoEsta=La llave no existe.

View File

@@ -10,7 +10,7 @@ public Enlace buscar(int llave) {
}
if (lista.getLlave() == llave) {
// Devoler el enlace encontrado.
// Devoler el listaEnlace encontrado.
return lista;
}
else {

View File

@@ -2,14 +2,14 @@ public void eliminar(int llave) {
if (primer != null) {
// Crear una lista temporario para trabajar
Enlace lista = this.primer;
// Guardar el enlace previo
// Guardar el listaEnlace previo
Enlace previo = lista;
// Solo busca mientras que i es menor que la cantidad de enlaces
int i = 0;
while (lista.getLlave() != llave && i < elementos) {
// Buscar hasta la llave es encontraddo
if (lista.getSiguente() != null) {
// Buscar en el sigenute enlace
// Buscar en el sigenute listaEnlace
previo = lista;
lista = lista.getSiguente();
}
@@ -23,11 +23,11 @@ public void eliminar(int llave) {
// Se encontró
if (lista == this.lista) {
// Si es el primer enlace, cambiarlo al siguente enlace
// Si es el primer listaEnlace, cambiarlo al siguente listaEnlace
this.lista = this.lista.getSiguente();
}
else {
// Sino cortar este enlace de la lista
// Sino cortar este listaEnlace de la lista
previo.setSiguente(lista.getSiguente());
}
elementos--;

View File

@@ -1,10 +1,10 @@
public void insertar(int llave) {
if (buscar(llave) == null) {
// Crear un enlace nuevo
// Crear un listaEnlace nuevo
Enlace nuevo = new Enlace(primer, llave);
if (primer == null) {
// Si el primer enlace es null, el ul
// Si el primer listaEnlace es null, el ul
ultimo = nuevo;
}

View File

@@ -5,7 +5,7 @@ public Enlace buscar(int llave) {
while (lista.getLlave() != llave) {
// Buscar hasta la llave es encontraddo
if (lista.getSiguente() != null) {
// Buscar en el sigenute enlace
// Buscar en el sigenute listaEnlace
lista = lista.getSiguente();
}
else {
@@ -13,7 +13,7 @@ public Enlace buscar(int llave) {
return null;
}
}
// Se encontró, devolver el enlace
// Se encontró, devolver el listaEnlace
return lista;
}
else {

View File

@@ -2,12 +2,12 @@ public void eliminar(int llave) {
if (lista != null) {
// Crear una lista temporario para trabajar
Enlace lista = this.lista;
// Guardar el enlace previo
// Guardar el listaEnlace previo
Enlace previo = lista;
while (lista.getLlave() != llave) {
// Buscar hasta la llave es encontraddo
if (lista.getSiguente() != null) {
// Buscar en el sigenute enlace
// Buscar en el sigenute listaEnlace
previo = lista;
lista = lista.getSiguente();
}
@@ -18,14 +18,14 @@ public void eliminar(int llave) {
}
// Se encontró
if (lista == this.lista) {
// Si es el primer enlace, cambiarlo al siguente enlace
// Si es el primer listaEnlace, cambiarlo al siguente listaEnlace
this.lista = this.lista.getSiguente();
if (this.lista.getPrevio() != null) {
this.lista.setPrevio(null);
}
}
else {
// Sino cortar este enlace de la lista
// Sino cortar este listaEnlace de la lista
previo.setSiguente(lista.getSiguente());
}
}

View File

@@ -1,12 +1,12 @@
public void insertar(int llave) {
if (buscar(llave) == null) {
// Crear un enlace nuevo
// Crear un listaEnlace nuevo
Enlace nuevo = new Enlace(lista, llave);
if (lista != null) {
// El previo es el nuevo.
lista.setPrevio(nuevo);
}
// Agregar el enlace a la lista
// Agregar el listaEnlace a la lista
lista = nuevo;
}
}

View File

@@ -5,7 +5,7 @@ public Enlace buscar(int llave) {
while (lista.getLlave() != llave) {
// Buscar hasta la llave es encontraddo
if (lista.getSiguente() != null) {
// Buscar en el sigenute enlace
// Buscar en el sigenute listaEnlace
lista = lista.getSiguente();
}
else {
@@ -13,7 +13,7 @@ public Enlace buscar(int llave) {
return null;
}
}
// Se encontró, devolver el enlace
// Se encontró, devolver el listaEnlace
return lista;
}
else {

View File

@@ -2,12 +2,12 @@ public void eliminar(int llave) {
if (lista != null) {
// Crear una lista temporario para trabajar
Enlace lista = this.lista;
// Guardar el enlace previo
// Guardar el listaEnlace previo
Enlace previo = lista;
while (lista.getLlave() != llave) {
// Buscar hasta la llave es encontraddo
if (lista.getSiguente() != null) {
// Buscar en el sigenute enlace
// Buscar en el sigenute listaEnlace
previo = lista;
lista = lista.getSiguente();
}
@@ -18,11 +18,11 @@ public void eliminar(int llave) {
}
// Se encontró
if (lista == this.lista) {
// Si es el primer enlace, cambiarlo al siguente enlace
// Si es el primer listaEnlace, cambiarlo al siguente listaEnlace
this.lista = this.lista.getSiguente();
}
else {
// Sino cortar este enlace de la lista
// Sino cortar este listaEnlace de la lista
previo.setSiguente(lista.getSiguente());
}
}

View File

@@ -1,8 +1,8 @@
public void insertar(int llave) {
if (buscar(llave) == null) {
// Crear un enlace nuevo
// Crear un listaEnlace nuevo
Enlace nuevo = new Enlace(lista, llave);
// Agregar el enlace a la lista
// Agregar el listaEnlace a la lista
lista = nuevo;
}
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import cl.cromer.estructuras.TextFieldLimited?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
<VBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="768.0" prefWidth="1024.0" spacing="10"
xmlns="http://javafx.com/javafx/8.0.92" fx:controller="cl.cromer.estructuras.ArbolController">
<fx:include source="menu.fxml"/>
<ScrollPane fitToHeight="true" fitToWidth="true" VBox.vgrow="ALWAYS">
<HBox alignment="TOP_CENTER" VBox.vgrow="ALWAYS" spacing="50">
<VBox spacing="10">
<HBox alignment="CENTER" spacing="10">
<!--<Button text="%llenar" onAction="#botonLlenar"/>-->
<!--<Button text="%vaciar" onAction="#botonVaciar"/>-->
</HBox>
<HBox alignment="CENTER" spacing="10">
<Button text="%insertar" onAction="#botonInsertar"/>
<!--<Button text="%pop" onAction="#botonPop"/>-->
<!--<Button text="%peek" onAction="#botonPeek"/>-->
<TextFieldLimited fx:id="valorArbol" maxLength="3" prefWidth="50"/>
</HBox>
<GridPane fx:id="contenidoArbol" alignment="CENTER"/>
</VBox>
<StackPane alignment="TOP_LEFT" minWidth="450">
<Text fx:id="codigoArbol"/>
</StackPane>
</HBox>
</ScrollPane>
</VBox>

View File

@@ -24,7 +24,7 @@
<MenuItem text="%pila" onAction="#menuPila"/>
<MenuItem text="%cola" onAction="#menuCola"/>
<Menu text="%arboles">
<MenuItem text="%general"/>
<MenuItem text="%general" onAction="#menuArbolGeneral"/>
<MenuItem text="%binario"/>
<MenuItem text="%busquedaBinario"/>
<MenuItem text="%AVL"/>