diff --git a/.idea/artifacts/Estructuras_de_Datos.xml b/.idea/artifacts/Estructuras_de_Datos.xml
index f3a13d0..dc856ba 100644
--- a/.idea/artifacts/Estructuras_de_Datos.xml
+++ b/.idea/artifacts/Estructuras_de_Datos.xml
@@ -27,10 +27,17 @@
+
+
+
+
+
+
+
+
-
-
+
diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
index c4c9543..46f91bb 100644
--- a/.idea/codeStyleSettings.xml
+++ b/.idea/codeStyleSettings.xml
@@ -2,8 +2,12 @@
-
+
\ No newline at end of file
diff --git a/estructuras_de_datos.xml b/estructuras_de_datos.xml
index edbfb8f..bc08965 100644
--- a/estructuras_de_datos.xml
+++ b/estructuras_de_datos.xml
@@ -1,269 +1,250 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
index 2559fe9..b422400 100644
--- a/src/META-INF/MANIFEST.MF
+++ b/src/META-INF/MANIFEST.MF
@@ -1,7 +1,8 @@
Manifest-Version: 1.0
Permissions: sandbox
+Codebase: *.cromer.cl 127.0.0.1
JavaFX-Version: 8.0
Class-Path: /cl/cromer/estructuras
Created-By: Chris Cromer
Main-Class: cl.cromer.estructuras.Main
-
+Application-Name: Estructuras de Datos
diff --git a/src/cl/cromer/estructuras/Array.java b/src/cl/cromer/estructuras/Array.java
index 29da2c6..4f1aebb 100644
--- a/src/cl/cromer/estructuras/Array.java
+++ b/src/cl/cromer/estructuras/Array.java
@@ -52,6 +52,28 @@ final public class Array {
this.ordered = ordered;
}
+ /**
+ * Insertar un valor al array.
+ *
+ * @param valor int: El valor a insertar.
+ *
+ * @return boolean: Verdad si fue exitoso, sino falso.
+ */
+ public boolean insertar(int valor) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == null) {
+ array[i] = String.valueOf(valor);
+ size++;
+ return true;
+ }
+ else if (array[i].equals(String.valueOf(valor))) {
+ // Ya existe el valor en el array
+ return false;
+ }
+ }
+ return false;
+ }
+
/**
* Eliminar un valor del array si existe.
*
@@ -85,18 +107,29 @@ final public class Array {
}
/**
- * Devolver el valor que está guardado en cada indice del array. Se usa para construir la grafica.
+ * Buscar si existe un valor dentro el array.
*
- * @param indice int: El indice que desea ver.
+ * @param valor int: Valor a buscar.
*
- * @return String: El valor que está en dicho indice.
+ * @return int: Devuelve el indice donde fue encontrado, o -1 si no fue encontrado.
*/
- public String getIndice(int indice) {
- if (indice >= 0 && indice < array.length) {
- return array[indice];
+ public int buscar(int valor) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != null && array[i].equals(String.valueOf(valor))) {
+ // Se encontró
+ return i;
+ }
}
- else {
- return null;
+ // No se encontró
+ return - 1;
+ }
+
+ /**
+ * Borrar el array para que sea como nuevo.
+ */
+ public void nuevo() {
+ for (int i = 0; i < size(); i++) {
+ array[i] = null;
}
}
@@ -118,6 +151,22 @@ final public class Array {
}
}
+ /**
+ * Devolver el valor que está guardado en cada indice del array. Se usa para construir la grafica.
+ *
+ * @param indice int: El indice que desea ver.
+ *
+ * @return String: El valor que está en dicho indice.
+ */
+ public String getIndice(int indice) {
+ if (indice >= 0 && indice < array.length) {
+ return array[indice];
+ }
+ else {
+ return null;
+ }
+ }
+
/**
* Devolver la cantidad de elementos en el array.
*
@@ -127,55 +176,6 @@ final public class Array {
return size;
}
- /**
- * Buscar si existe un valor dentro el array.
- *
- * @param valor int: Valor a buscar.
- *
- * @return int: Devuelve el indice donde fue encontrado, o -1 si no fue encontrado.
- */
- public int buscar(int valor) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] != null && array[i].equals(String.valueOf(valor))) {
- // Se encontró
- return i;
- }
- }
- // No se encontró
- return - 1;
- }
-
- /**
- * Insertar un valor al array.
- *
- * @param valor int: El valor a insertar.
- *
- * @return boolean: Verdad si fue exitoso, sino falso.
- */
- public boolean insertar(int valor) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == null) {
- array[i] = String.valueOf(valor);
- size++;
- return true;
- }
- else if (array[i].equals(String.valueOf(valor))) {
- // Ya existe el valor en el array
- return false;
- }
- }
- return false;
- }
-
- /**
- * Borrar el array.
- */
- public void nuevo() {
- for (int i = 0; i < size(); i++) {
- array[i] = null;
- }
- }
-
/**
* Ordenar el array usando burbuja.
*
diff --git a/src/cl/cromer/estructuras/ArrayController.java b/src/cl/cromer/estructuras/ArrayController.java
index bf136e0..caac280 100644
--- a/src/cl/cromer/estructuras/ArrayController.java
+++ b/src/cl/cromer/estructuras/ArrayController.java
@@ -18,233 +18,233 @@ import java.util.logging.Level;
*/
public class ArrayController implements Initializable {
- /**
- * La caja para ingresar textos.
- */
- @FXML
- private TextFieldLimited valorArray;
+ /**
+ * La caja para ingresar textos.
+ */
+ @FXML
+ private TextFieldLimited valorArray;
- /**
- * Donde poner el contenido de array.
- */
- @FXML
- private VBox contenidoArray;
+ /**
+ * Donde poner el contenido de array.
+ */
+ @FXML
+ private VBox contenidoArray;
- /**
- * Donde va el codigo a mostrar a la pantalla.
- */
- @FXML
- private Text codigoArray;
+ /**
+ * Donde va el codigo a mostrar a la pantalla.
+ */
+ @FXML
+ private Text codigoArray;
- /**
- * La escena donde está cosas graficas.
- */
- private Scene scene;
+ /**
+ * La escena donde está cosas graficas.
+ */
+ private Scene scene;
- /**
- * Donde está guardado los idiomas.
- */
- private ResourceBundle resourceBundle;
+ /**
+ * Donde está guardado los idiomas.
+ */
+ private ResourceBundle resourceBundle;
- /**
- * El array usado en la aplicación.
- */
- private Array array;
+ /**
+ * El array usado en la aplicación.
+ */
+ private Array array;
- /**
- * Grafico rectangulos.
- */
- private Grafico grafico;
+ /**
+ * 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;
+ /**
+ * 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;
- scene = null;
- Colores colores = new Colores();
+ scene = null;
+ Colores colores = new Colores();
- for (int i = 0; i < 10; i++) {
- contenidoArray.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i)));
- colores.siguinteColor();
- }
- }
+ for (int i = 0; i < 10; i++) {
+ contenidoArray.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i)));
+ colores.siguinteColor();
+ }
+ }
- /**
- * Llenar el array con numeros al azar.
- */
- @FXML
- protected void botonLlenar() {
- if (scene == null) {
- initializeArray();
- }
+ /**
+ * Llenar el array con numeros al azar.
+ */
+ @FXML
+ protected void botonLlenar() {
+ if (scene == null) {
+ initializeArray();
+ }
- array.llenar();
- generarGrafico();
- }
+ array.llenar();
+ generarGrafico();
+ }
- /**
- * Crear el array de tamaño 10. La scene está usado para saber si es de tipo ordenado o simple segun el ménu.
- */
- private void initializeArray() {
- scene = contenidoArray.getScene();
- grafico = new Grafico(scene);
- this.array = new Array(10);
- ArrayTipos arrayTipos = (ArrayTipos) scene.getUserData();
- if (arrayTipos.getTipo() == ArrayTipos.ORDENADO) {
- this.array.setOrdered(true);
- }
- }
+ /**
+ * Vaciar el array de todos los valores.
+ */
+ @FXML
+ protected void botonVaciar() {
+ if (scene == null) {
+ initializeArray();
+ }
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- grafico.removerDestacar();
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(array.getIndice(i));
- }
- }
+ if (array.isOrdered()) {
+ array = new Array(10);
+ array.setOrdered(true);
+ }
+ else {
+ array = new Array(10);
+ array.setOrdered(false);
+ }
+ generarGrafico();
+ }
- /**
- * Vaciar el array de todos los valores.
- */
- @FXML
- protected void botonVaciar() {
- if (scene == null) {
- initializeArray();
- }
+ /**
+ * Insertar un valor al array y mostrar el codigo en la pantalla.
+ */
+ @FXML
+ protected void botonInsertar() {
+ if (scene == null) {
+ initializeArray();
+ }
- if (array.isOrdered()) {
- array = new Array(10);
- array.setOrdered(true);
- }
- else {
- array = new Array(10);
- array.setOrdered(false);
- }
- generarGrafico();
- }
+ // Mostrar el codigo
+ String tipo = (array.isOrdered()) ? "Ordenado" : "Simple";
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/insertar")).useDelimiter("\\Z").next();
+ codigoArray.setText(codigoTexto);
- /**
- * Insertar un valor al array y mostrar el codigo en la pantalla.
- */
- @FXML
- protected void botonInsertar() {
- if (scene == null) {
- initializeArray();
- }
+ if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) {
+ try {
+ boolean exito = array.insertar(Integer.valueOf(valorArray.getText()));
+ if (exito) {
+ valorArray.setText("");
+ generarGrafico();
+ }
+ else {
+ if (array.size() == 10) {
+ Main.mostrarError(resourceBundle.getString("arrayLleno"), resourceBundle);
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("arrayValorExiste"), resourceBundle);
+ }
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
+ }
+ }
- // Mostrar el codigo
- String tipo = (array.isOrdered()) ? "Ordenado" : "Simple";
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/insertar")).useDelimiter("\\Z").next();
- codigoArray.setText(codigoTexto);
+ /**
+ * Eliminar un valor del array si existe y mostrar el codigo en la pantalla.
+ */
+ @FXML
+ protected void botonEliminar() {
+ if (scene == null) {
+ initializeArray();
+ }
- if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) {
- try {
- boolean exito = array.insertar(Integer.valueOf(valorArray.getText()));
- if (exito) {
- valorArray.setText("");
- generarGrafico();
- }
- else {
- if (array.size() == 10) {
- Main.mostrarError(resourceBundle.getString("arrayLleno"), resourceBundle);
- }
- else {
- Main.mostrarError(resourceBundle.getString("arrayValorExiste"), resourceBundle);
- }
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
- }
- }
+ // Mostrar el codigo
+ String tipo = (array.isOrdered()) ? "Ordenado" : "Simple";
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/eliminar")).useDelimiter("\\Z").next();
+ codigoArray.setText(codigoTexto);
- /**
- * Eliminar un valor del array si existe y mostrar el codigo en la pantalla.
- */
- @FXML
- protected void botonEliminar() {
- if (scene == null) {
- initializeArray();
- }
+ try {
+ if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) {
+ boolean exito = array.eliminar(Integer.valueOf(valorArray.getText()));
+ if (exito) {
+ valorArray.setText("");
+ generarGrafico();
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("arrayNoEsta"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
+ }
+ }
- // Mostrar el codigo
- String tipo = (array.isOrdered()) ? "Ordenado" : "Simple";
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/eliminar")).useDelimiter("\\Z").next();
- codigoArray.setText(codigoTexto);
+ /**
+ * Buscar si existe un elemento en el array y mostrar el codigo en la pantalla
+ * Si existe el valor destacarlo.
+ */
+ @FXML
+ protected void botonBuscar() {
+ if (scene == null) {
+ initializeArray();
+ }
- try {
- if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) {
- boolean exito = array.eliminar(Integer.valueOf(valorArray.getText()));
- if (exito) {
- valorArray.setText("");
- generarGrafico();
- }
- else {
- Main.mostrarError(resourceBundle.getString("arrayNoEsta"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
- }
- }
+ // Mostrar el codigo
+ String tipo = (array.isOrdered()) ? "Ordenado" : "Simple";
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/buscar")).useDelimiter("\\Z").next();
+ codigoArray.setText(codigoTexto);
- /**
- * Buscar si existe un elemento en el array y mostrar el codigo en la pantalla
- * Si existe el valor destacarlo.
- */
- @FXML
- protected void botonBuscar() {
- if (scene == null) {
- initializeArray();
- }
+ try {
+ if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) {
+ int encontrado = array.buscar(Integer.valueOf(valorArray.getText()));
+ if (encontrado != - 1) {
+ generarGrafico();
+ grafico = new Grafico(scene);
+ grafico.destacar("#caja_" + encontrado, Grafico.RECTANGULO);
+ grafico.destacar("#texto_" + encontrado, Grafico.TEXTO);
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("arrayNoEsta"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
+ }
+ }
- // Mostrar el codigo
- String tipo = (array.isOrdered()) ? "Ordenado" : "Simple";
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/buscar")).useDelimiter("\\Z").next();
- codigoArray.setText(codigoTexto);
+ /**
+ * Crear el array de tamaño 10. La scene está usado para saber si es de tipo ordenado o simple segun el ménu.
+ */
+ private void initializeArray() {
+ scene = contenidoArray.getScene();
+ grafico = new Grafico(scene);
+ this.array = new Array(10);
+ ArrayTipos arrayTipos = (ArrayTipos) scene.getUserData();
+ if (arrayTipos.getTipo() == ArrayTipos.ORDENADO) {
+ this.array.setOrdered(true);
+ }
+ }
- try {
- if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) {
- int encontrado = array.buscar(Integer.valueOf(valorArray.getText()));
- if (encontrado != - 1) {
- generarGrafico();
- grafico = new Grafico(scene);
- grafico.destacar("#caja_" + encontrado, Grafico.RECTANGULO);
- grafico.destacar("#texto_" + encontrado, Grafico.TEXTO);
- }
- else {
- Main.mostrarError(resourceBundle.getString("arrayNoEsta"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle);
- }
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ grafico.removerDestacar();
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(array.getIndice(i));
+ }
}
}
diff --git a/src/cl/cromer/estructuras/BurbujaController.java b/src/cl/cromer/estructuras/BurbujaController.java
index c01b95f..32521e5 100644
--- a/src/cl/cromer/estructuras/BurbujaController.java
+++ b/src/cl/cromer/estructuras/BurbujaController.java
@@ -16,126 +16,126 @@ import java.util.Scanner;
* @author Chris Cromer
*/
public class BurbujaController implements Initializable {
- /**
- * Donde poner el contenido de array.
- */
- @FXML
- private HBox contenidoBurbuja;
+ /**
+ * Donde poner el contenido de array.
+ */
+ @FXML
+ private HBox contenidoBurbuja;
- /**
- * Donde va el codigo a mostrar a la pantalla.
- */
- @FXML
- private Text codigoBurbuja;
+ /**
+ * Donde va el codigo a mostrar a la pantalla.
+ */
+ @FXML
+ private Text codigoBurbuja;
- /**
- * La escena donde está cosas graficas.
- */
- private Scene scene;
+ /**
+ * La escena donde está cosas graficas.
+ */
+ private Scene scene;
- /**
- * Donde está guardado los idiomas.
- */
- private ResourceBundle resourceBundle;
+ /**
+ * Donde está guardado los idiomas.
+ */
+ private ResourceBundle resourceBundle;
- /**
- * El array usado en la aplicación.
- */
- private Array array;
+ /**
+ * El array usado en la aplicación.
+ */
+ private Array array;
- /**
- * 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
- @SuppressWarnings("Duplicates")
- public void initialize(URL location, ResourceBundle resourceBundle) {
- this.resourceBundle = resourceBundle;
+ /**
+ * 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
+ @SuppressWarnings("Duplicates")
+ public void initialize(URL location, ResourceBundle resourceBundle) {
+ this.resourceBundle = resourceBundle;
- scene = null;
+ scene = null;
- Colores colores = new Colores();
+ Colores colores = new Colores();
- array = new Array(10);
- array.setOrdered(true);
- array.llenar();
+ array = new Array(10);
+ array.setOrdered(true);
+ array.llenar();
- for (int i = 0; i < 10; i++) {
- contenidoBurbuja.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
- colores.siguinteColor();
- }
- }
+ for (int i = 0; i < 10; i++) {
+ contenidoBurbuja.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
+ colores.siguinteColor();
+ }
+ }
- /**
- * Crear un array nuevo.
- */
- @FXML
- protected void botonNuevo() {
- if (scene == null) {
- initializeScene();
- }
+ /**
+ * Crear un array nuevo.
+ */
+ @FXML
+ protected void botonNuevo() {
+ if (scene == null) {
+ initializeScene();
+ }
- array.nuevo();
- array.llenar();
- generarGrafico();
- }
+ array.nuevo();
+ array.llenar();
+ generarGrafico();
+ }
- /**
- * Crear el array de tamaño 10.
- */
- private void initializeScene() {
- scene = contenidoBurbuja.getScene();
- }
+ /**
+ * Ordenarlo paso por paso.
+ */
+ @FXML
+ protected void botonPaso() {
+ if (scene == null) {
+ initializeScene();
+ }
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(array.getIndice(i));
- }
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/burbuja/ordenar")).useDelimiter("\\Z").next();
+ codigoBurbuja.setText(codigoTexto);
- /**
- * Ordenarlo paso por paso.
- */
- @FXML
- protected void botonPaso() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/burbuja/ordenar")).useDelimiter("\\Z").next();
- codigoBurbuja.setText(codigoTexto);
-
- if (! array.burbuja(true)) {
- Main.mostrarError(resourceBundle.getString("burbujaYaOrdenado"), resourceBundle);
- }
-
- generarGrafico();
- }
-
- /**
- * Ordenarlo completamente.
- */
- @FXML
- protected void botonCorrer() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/burbuja/ordenar")).useDelimiter("\\Z").next();
- codigoBurbuja.setText(codigoTexto);
-
- if (! array.burbuja(false)) {
- Main.mostrarError(resourceBundle.getString("burbujaYaOrdenado"), resourceBundle);
- }
+ if (! array.burbuja(true)) {
+ Main.mostrarError(resourceBundle.getString("burbujaYaOrdenado"), resourceBundle);
+ }
generarGrafico();
- }
+ }
+
+ /**
+ * Ordenarlo completamente.
+ */
+ @FXML
+ protected void botonCorrer() {
+ if (scene == null) {
+ initializeScene();
+ }
+
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/burbuja/ordenar")).useDelimiter("\\Z").next();
+ codigoBurbuja.setText(codigoTexto);
+
+ if (! array.burbuja(false)) {
+ Main.mostrarError(resourceBundle.getString("burbujaYaOrdenado"), resourceBundle);
+ }
+
+ generarGrafico();
+ }
+
+ /**
+ * Crear el array de tamaño 10.
+ */
+ private void initializeScene() {
+ scene = contenidoBurbuja.getScene();
+ }
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(array.getIndice(i));
+ }
+ }
}
diff --git a/src/cl/cromer/estructuras/Cola.java b/src/cl/cromer/estructuras/Cola.java
index 538b007..0db9979 100644
--- a/src/cl/cromer/estructuras/Cola.java
+++ b/src/cl/cromer/estructuras/Cola.java
@@ -26,6 +26,30 @@ final public class Cola {
size = 0;
}
+ /**
+ * Push un valor en la cola encima.
+ *
+ * @param valor int: El valor a push.
+ */
+ public void push(int valor) {
+ if (this.cola != null) {
+ String cola[] = new String[this.cola.length + 1];
+ int i;
+ for (i = 0; i < this.cola.length; i++) {
+ cola[i] = this.cola[i];
+ }
+ cola[i] = String.valueOf(valor);
+ this.cola = cola;
+ size++;
+ }
+ else {
+ String pila[] = new String[1];
+ pila[0] = String.valueOf(valor);
+ this.cola = pila;
+ size++;
+ }
+ }
+
/**
* Pop un valor del principio de la cola.
*
@@ -59,6 +83,22 @@ final public class Cola {
}
}
+ /**
+ * Llenar la cola con valores al azar.
+ */
+ @SuppressWarnings("Duplicates")
+ public void llenar() {
+ Random random = new Random();
+ int maximo = 99;
+ int minimo = 0;
+ int rango = maximo - minimo + 1;
+
+ for (int i = size(); i < 10; i++) {
+ int numero = random.nextInt(rango) + minimo;
+ push(numero);
+ }
+ }
+
/**
* Devolver la cantidad de elementos que están en la cola.
*
@@ -83,44 +123,4 @@ final public class Cola {
return null;
}
}
-
- /**
- * Llenar la cola con valores al azar.
- */
- @SuppressWarnings("Duplicates")
- public void llenar() {
- Random random = new Random();
- int maximo = 99;
- int minimo = 0;
- int rango = maximo - minimo + 1;
-
- for (int i = size(); i < 10; i++) {
- int numero = random.nextInt(rango) + minimo;
- push(numero);
- }
- }
-
- /**
- * Push un valor en la cola encima.
- *
- * @param valor int: El valor a push.
- */
- public void push(int valor) {
- if (this.cola != null) {
- String cola[] = new String[this.cola.length + 1];
- int i;
- for (i = 0; i < this.cola.length; i++) {
- cola[i] = this.cola[i];
- }
- cola[i] = String.valueOf(valor);
- this.cola = cola;
- size++;
- }
- else {
- String pila[] = new String[1];
- pila[0] = String.valueOf(valor);
- this.cola = pila;
- size++;
- }
- }
}
diff --git a/src/cl/cromer/estructuras/ColaController.java b/src/cl/cromer/estructuras/ColaController.java
index 7f9c930..c43d66d 100644
--- a/src/cl/cromer/estructuras/ColaController.java
+++ b/src/cl/cromer/estructuras/ColaController.java
@@ -90,17 +90,6 @@ public class ColaController implements Initializable {
generarGrafico();
}
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- grafico.removerDestacar();
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(cola.getIndice(i));
- }
- }
-
/**
* Vaciar la cola de todos los valores.
*/
@@ -203,4 +192,15 @@ public class ColaController implements Initializable {
Main.mostrarError(resourceBundle.getString("colaVacia"), resourceBundle);
}
}
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ grafico.removerDestacar();
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(cola.getIndice(i));
+ }
+ }
}
\ No newline at end of file
diff --git a/src/cl/cromer/estructuras/InsercionController.java b/src/cl/cromer/estructuras/InsercionController.java
index e72a0ef..f4773bf 100644
--- a/src/cl/cromer/estructuras/InsercionController.java
+++ b/src/cl/cromer/estructuras/InsercionController.java
@@ -16,126 +16,126 @@ import java.util.Scanner;
* @author Chris Cromer
*/
public class InsercionController implements Initializable {
- /**
- * Donde poner el contenido de array.
- */
- @FXML
- private HBox contenidoInsercion;
+ /**
+ * Donde poner el contenido de array.
+ */
+ @FXML
+ private HBox contenidoInsercion;
- /**
- * Donde va el codigo a mostrar a la pantalla.
- */
- @FXML
- private Text codigoInsercion;
+ /**
+ * Donde va el codigo a mostrar a la pantalla.
+ */
+ @FXML
+ private Text codigoInsercion;
- /**
- * La escena donde está cosas graficas.
- */
- private Scene scene;
+ /**
+ * La escena donde está cosas graficas.
+ */
+ private Scene scene;
- /**
- * Donde está guardado los idiomas.
- */
- private ResourceBundle resourceBundle;
+ /**
+ * Donde está guardado los idiomas.
+ */
+ private ResourceBundle resourceBundle;
- /**
- * El array usado en la aplicación.
- */
- private Array array;
+ /**
+ * El array usado en la aplicación.
+ */
+ private Array array;
- /**
- * 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
- @SuppressWarnings("Duplicates")
- public void initialize(URL location, ResourceBundle resourceBundle) {
- this.resourceBundle = resourceBundle;
+ /**
+ * 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
+ @SuppressWarnings("Duplicates")
+ public void initialize(URL location, ResourceBundle resourceBundle) {
+ this.resourceBundle = resourceBundle;
- scene = null;
+ scene = null;
- Colores colores = new Colores();
+ Colores colores = new Colores();
- array = new Array(10);
- array.setOrdered(true);
- array.llenar();
+ array = new Array(10);
+ array.setOrdered(true);
+ array.llenar();
- for (int i = 0; i < 10; i++) {
- contenidoInsercion.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
- colores.siguinteColor();
- }
- }
+ for (int i = 0; i < 10; i++) {
+ contenidoInsercion.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
+ colores.siguinteColor();
+ }
+ }
- /**
- * Crear un array nuevo.
- */
- @FXML
- protected void botonNuevo() {
- if (scene == null) {
- initializeScene();
- }
+ /**
+ * Crear un array nuevo.
+ */
+ @FXML
+ protected void botonNuevo() {
+ if (scene == null) {
+ initializeScene();
+ }
- array.nuevo();
- array.llenar();
- generarGrafico();
- }
+ array.nuevo();
+ array.llenar();
+ generarGrafico();
+ }
- /**
- * Crear el array de tamaño 10.
- */
- private void initializeScene() {
- scene = contenidoInsercion.getScene();
- }
+ /**
+ * Ordenarlo paso por paso.
+ */
+ @FXML
+ protected void botonPaso() {
+ if (scene == null) {
+ initializeScene();
+ }
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(array.getIndice(i));
- }
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/insercion/ordenar")).useDelimiter("\\Z").next();
+ codigoInsercion.setText(codigoTexto);
- /**
- * Ordenarlo paso por paso.
- */
- @FXML
- protected void botonPaso() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/insercion/ordenar")).useDelimiter("\\Z").next();
- codigoInsercion.setText(codigoTexto);
-
- if (! array.insercion(true)) {
- Main.mostrarError(resourceBundle.getString("insercionYaOrdenado"), resourceBundle);
- }
-
- generarGrafico();
- }
-
- /**
- * Ordenarlo completamente.
- */
- @FXML
- protected void botonCorrer() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/insercion/ordenar")).useDelimiter("\\Z").next();
- codigoInsercion.setText(codigoTexto);
-
- if (! array.insercion(false)) {
- Main.mostrarError(resourceBundle.getString("insercionYaOrdenado"), resourceBundle);
- }
+ if (! array.insercion(true)) {
+ Main.mostrarError(resourceBundle.getString("insercionYaOrdenado"), resourceBundle);
+ }
generarGrafico();
- }
+ }
+
+ /**
+ * Ordenarlo completamente.
+ */
+ @FXML
+ protected void botonCorrer() {
+ if (scene == null) {
+ initializeScene();
+ }
+
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/insercion/ordenar")).useDelimiter("\\Z").next();
+ codigoInsercion.setText(codigoTexto);
+
+ if (! array.insercion(false)) {
+ Main.mostrarError(resourceBundle.getString("insercionYaOrdenado"), resourceBundle);
+ }
+
+ generarGrafico();
+ }
+
+ /**
+ * Crear el array de tamaño 10.
+ */
+ private void initializeScene() {
+ scene = contenidoInsercion.getScene();
+ }
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(array.getIndice(i));
+ }
+ }
}
diff --git a/src/cl/cromer/estructuras/ListaEnlazada.java b/src/cl/cromer/estructuras/ListaEnlazada.java
index abde781..2dbe5ab 100644
--- a/src/cl/cromer/estructuras/ListaEnlazada.java
+++ b/src/cl/cromer/estructuras/ListaEnlazada.java
@@ -72,37 +72,6 @@ final public class ListaEnlazada {
}
}
- /**
- * Buscar una llave en la lista.
- *
- * @param llave int: La llave a buscar.
- *
- * @return Enlace: El enlace que contiene la llave buscada.
- */
- public Enlace buscar(int llave) {
- if (this.lista != null) {
- // La lista no es vacia
- Enlace 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();
- }
- else {
- // No se encuentra
- return null;
- }
- }
- // Se encontró
- return lista;
- }
- else {
- // La lista es vacia, nada para buscar
- return null;
- }
- }
-
/**
* Eliminar un enlace de la lista.
*
@@ -148,6 +117,37 @@ final public class ListaEnlazada {
}
}
+ /**
+ * Buscar una llave en la lista.
+ *
+ * @param llave int: La llave a buscar.
+ *
+ * @return Enlace: El enlace que contiene la llave buscada.
+ */
+ public Enlace buscar(int llave) {
+ if (this.lista != null) {
+ // La lista no es vacia
+ Enlace 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();
+ }
+ else {
+ // No se encuentra
+ return null;
+ }
+ }
+ // Se encontró
+ return lista;
+ }
+ else {
+ // La lista es vacia, nada para buscar
+ return null;
+ }
+ }
+
/**
* Devolver un enlace con su llave y valor.
*
diff --git a/src/cl/cromer/estructuras/ListaEnlazadaCircular.java b/src/cl/cromer/estructuras/ListaEnlazadaCircular.java
index 1acf707..30feb81 100644
--- a/src/cl/cromer/estructuras/ListaEnlazadaCircular.java
+++ b/src/cl/cromer/estructuras/ListaEnlazadaCircular.java
@@ -82,47 +82,6 @@ final public class ListaEnlazadaCircular {
}
}
- /**
- * Buscar una llave en la lista.
- *
- * @param llave int: La llave a buscar.
- *
- * @return Enlace: El enlace que contiene la llave.
- */
- public Enlace buscar(int llave) {
- if (this.primer != null) {
- // La lista no es vacia
- Enlace lista = this.primer;
- int i = 0;
- while (lista.getLlave() != llave && i < size()) {
- // Buscar en la sigenute enlace hasta el final.
- lista = (Enlace) lista.getSiguiente();
- i++;
- }
- if (lista.getLlave() == llave) {
- // Devoler el enlace encontrado.
- return lista;
- }
- else {
- // No se encontró.
- return null;
- }
- }
- else {
- // La lista es vacia, nada para buscar
- return null;
- }
- }
-
- /**
- * Devolver la cantidad de enlaces que están en la lista.
- *
- * @return int: La cantidad.
- */
- public int size() {
- return size;
- }
-
/**
* Eliminar un enlace de la lista.
*
@@ -169,6 +128,47 @@ final public class ListaEnlazadaCircular {
}
}
+ /**
+ * Buscar una llave en la lista.
+ *
+ * @param llave int: La llave a buscar.
+ *
+ * @return Enlace: El enlace que contiene la llave.
+ */
+ public Enlace buscar(int llave) {
+ if (this.primer != null) {
+ // La lista no es vacia
+ Enlace lista = this.primer;
+ int i = 0;
+ while (lista.getLlave() != llave && i < size()) {
+ // Buscar en la sigenute enlace hasta el final.
+ lista = (Enlace) lista.getSiguiente();
+ i++;
+ }
+ if (lista.getLlave() == llave) {
+ // Devoler el enlace encontrado.
+ return lista;
+ }
+ else {
+ // No se encontró.
+ return null;
+ }
+ }
+ else {
+ // La lista es vacia, nada para buscar
+ return null;
+ }
+ }
+
+ /**
+ * Devolver la cantidad de enlaces que están en la lista.
+ *
+ * @return int: La cantidad.
+ */
+ public int size() {
+ return size;
+ }
+
/**
* Devolver un enlace con su llave y valor.
*
diff --git a/src/cl/cromer/estructuras/ListaEnlazdaController.java b/src/cl/cromer/estructuras/ListaEnlazdaController.java
index e599898..284eed5 100644
--- a/src/cl/cromer/estructuras/ListaEnlazdaController.java
+++ b/src/cl/cromer/estructuras/ListaEnlazdaController.java
@@ -18,374 +18,374 @@ import java.util.logging.Level;
* @author Chris Cromer
*/
public class ListaEnlazdaController implements Initializable {
- /**
- * La caja para ingresar el valor.
- */
- @FXML
- private TextFieldLimited valorLista;
+ /**
+ * La caja para ingresar el valor.
+ */
+ @FXML
+ private TextFieldLimited valorLista;
- /**
- * Donde poner el contenido de lista.
- */
- @FXML
- private VBox contenidoLista;
+ /**
+ * Donde poner el contenido de lista.
+ */
+ @FXML
+ private VBox contenidoLista;
- /**
- * Donde poner el contenido de lista circular.
- */
- @FXML
- private VBox contenidoListaCircular;
+ /**
+ * Donde poner el contenido de lista circular.
+ */
+ @FXML
+ private VBox contenidoListaCircular;
- /**
- * Donde va el codigo a mostrar a la pantalla.
- */
- @FXML
- private Text codigoLista;
+ /**
+ * Donde va el codigo a mostrar a la pantalla.
+ */
+ @FXML
+ private Text codigoLista;
- /**
- * La escena donde está cosas graficas.
- */
- private Scene scene;
+ /**
+ * La escena donde está cosas graficas.
+ */
+ private Scene scene;
- /**
- * Donde está guardado los idiomas.
- */
- private ResourceBundle resourceBundle;
+ /**
+ * Donde está guardado los idiomas.
+ */
+ private ResourceBundle resourceBundle;
- /**
- * La lista enlazada usado en la aplicación.
- */
- private ListaEnlazada listaEnlazada;
+ /**
+ * La lista enlazada usado en la aplicación.
+ */
+ private ListaEnlazada listaEnlazada;
- /**
- * La lista enlazada circular usado en la aplicación.
- */
- private ListaEnlazadaCircular listaEnlazadaCircular;
+ /**
+ * La lista enlazada circular usado en la aplicación.
+ */
+ private ListaEnlazadaCircular listaEnlazadaCircular;
- /**
- * Tipo de lista enlazada a trabajar.
- */
- private ListaEnlazadaTipos listaEnlazadaTipos;
+ /**
+ * Tipo de lista enlazada a trabajar.
+ */
+ private ListaEnlazadaTipos listaEnlazadaTipos;
- /**
- * Grafico rectangulos y lineas.
- */
- private Grafico grafico;
+ /**
+ * Grafico rectangulos y lineas.
+ */
+ private Grafico grafico;
- /**
- * Colores por los dibjos.
- */
- private Colores colores;
+ /**
+ * Colores por los dibjos.
+ */
+ private Colores colores;
- /**
- * 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;
+ /**
+ * 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;
- scene = null;
- }
+ scene = null;
+ }
- /**
- * Llenar la lista con numeros al azar.
- */
- @FXML
- protected void botonLlenar() {
- if (scene == null) {
- initializeLista();
- }
+ /**
+ * Llenar la lista con numeros al azar.
+ */
+ @FXML
+ protected void botonLlenar() {
+ if (scene == null) {
+ initializeLista();
+ }
- Random random = new Random();
- int maximo = 99;
- int minimo = 0;
- int rango = maximo - minimo + 1;
+ Random random = new Random();
+ int maximo = 99;
+ int minimo = 0;
+ int rango = maximo - minimo + 1;
- if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
- for (listaEnlazada.size(); listaEnlazada.size() < 5; ) {
- int numero = random.nextInt(rango) + minimo;
- while (listaEnlazada.buscar(numero) != null) {
- numero = random.nextInt(rango) + minimo;
- }
- listaEnlazada.insertar(numero);
- }
- }
- else {
- for (listaEnlazadaCircular.size(); listaEnlazadaCircular.size() < 5; ) {
- int numero = random.nextInt(rango) + minimo;
- while (listaEnlazadaCircular.buscar(numero) != null) {
- numero = random.nextInt(rango) + minimo;
- }
- listaEnlazadaCircular.insertar(numero);
- }
- }
- generarGrafico();
- }
+ if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
+ for (listaEnlazada.size(); listaEnlazada.size() < 5; ) {
+ int numero = random.nextInt(rango) + minimo;
+ while (listaEnlazada.buscar(numero) != null) {
+ numero = random.nextInt(rango) + minimo;
+ }
+ listaEnlazada.insertar(numero);
+ }
+ }
+ else {
+ for (listaEnlazadaCircular.size(); listaEnlazadaCircular.size() < 5; ) {
+ int numero = random.nextInt(rango) + minimo;
+ while (listaEnlazadaCircular.buscar(numero) != null) {
+ numero = random.nextInt(rango) + minimo;
+ }
+ listaEnlazadaCircular.insertar(numero);
+ }
+ }
+ generarGrafico();
+ }
- /**
- * Crear una lista vacia.
- */
- private void initializeLista() {
- scene = contenidoLista.getScene();
- grafico = new Grafico(scene);
- listaEnlazadaTipos = (ListaEnlazadaTipos) scene.getUserData();
- nuevaLista();
- }
+ /**
+ * Vaciar la lista de todos los valores.
+ */
+ @FXML
+ protected void botonVaciar() {
+ if (scene == null) {
+ initializeLista();
+ }
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- grafico.removerDestacar();
- colores = new Colores();
- contenidoLista.getChildren().clear();
- contenidoListaCircular.getChildren().clear();
+ nuevaLista();
+ generarGrafico();
+ }
- if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
- for (int i = 0; i < listaEnlazada.size(); i++) {
- Enlace enlace = listaEnlazada.getIndice(i);
- if (listaEnlazada.getTipo() == ListaEnlazadaTipos.SIMPLE) {
- dibujarSimple(enlace, false);
- }
- else if (listaEnlazada.getTipo() == ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA) {
- if (i != listaEnlazada.size() - 1) {
- dibujarDoble(enlace, (i == 0));
- }
- else {
- dibujarSimple(enlace, false);
- }
- }
- colores.siguinteColor();
- }
- }
- else {
- for (int i = 0; i < listaEnlazadaCircular.size(); i++) {
- Enlace enlace = listaEnlazadaCircular.getIndice(i);
- dibujarSimple(enlace, (i == listaEnlazadaCircular.size() - 1));
- colores.siguinteColor();
- }
- if (listaEnlazadaCircular.size() > 0) {
- contenidoListaCircular.getChildren().addAll(Grafico.crearLineaCircular(listaEnlazadaCircular.size()));
- }
- }
- }
+ /**
+ * Insertar un valor a la lista y mostrar el codigo en la pantalla.
+ */
+ @FXML
+ protected void botonInsertar() {
+ if (scene == null) {
+ initializeLista();
+ }
- /**
- * Crear una nueva lista enlazada.
- */
- private void nuevaLista() {
- if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
- listaEnlazada = new ListaEnlazada();
- listaEnlazada.setTipo(listaEnlazadaTipos.getTipo());
- }
- else {
- listaEnlazadaCircular = new ListaEnlazadaCircular();
- listaEnlazadaCircular.setTipo(ListaEnlazadaTipos.SIMPLE);
- }
- }
+ String tipo = getTipoString();
- /**
- * Dibujarlo con una flecha.
- *
- * @param enlace Enlace: El enlace que tiene la llave y valor.
- * @param sinFlecha boolean: Verdad si necesita dibujar una flecha.
- */
- private void dibujarSimple(Enlace enlace, boolean sinFlecha) {
- contenidoLista.getChildren().addAll(
- Grafico.crearCaja(colores, String.valueOf(enlace.getLlave()), String.valueOf(enlace.getLlave()))
- );
- if (! sinFlecha) {
- contenidoLista.getChildren().addAll(
- Grafico.crearLineaVertical(),
- Grafico.crearFlechaAbajo()
- );
- }
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/listaEnlazada" + tipo + "/insertar")).useDelimiter("\\Z").next();
+ codigoLista.setText(codigoTexto);
- /**
- * Dibujarlo con dos flechas.
- *
- * @param enlace Enlace: El enlace 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) {
- if (primer) {
- contenidoLista.getChildren().addAll(
- Grafico.crearFlechaArriba(),
- Grafico.crearLineaVertical()
- );
- }
- contenidoLista.getChildren().addAll(
- Grafico.crearCaja(colores, String.valueOf(enlace.getLlave()), String.valueOf(enlace.getLlave())),
- Grafico.crearFlechaArriba(),
- Grafico.crearLineaVertical(),
- Grafico.crearFlechaAbajo()
- );
- }
-
- /**
- * Vaciar la lista de todos los valores.
- */
- @FXML
- protected void botonVaciar() {
- if (scene == null) {
- initializeLista();
- }
-
- nuevaLista();
- generarGrafico();
- }
-
- /**
- * Insertar un valor a la lista y mostrar el codigo en la pantalla.
- */
- @FXML
- protected void botonInsertar() {
- if (scene == null) {
- initializeLista();
- }
-
- String tipo = getTipoString();
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/listaEnlazada" + tipo + "/insertar")).useDelimiter("\\Z").next();
- codigoLista.setText(codigoTexto);
-
- if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) {
- try {
- boolean exito;
- if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
- exito = listaEnlazada.insertar(Integer.valueOf(valorLista.getText()));
- }
- else {
- exito = listaEnlazadaCircular.insertar(Integer.valueOf(valorLista.getText()));
- }
- if (exito) {
- valorLista.setText("");
- generarGrafico();
- }
- else {
- Main.mostrarError(resourceBundle.getString("listaLlaveExiste"), resourceBundle);
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
- }
- }
-
- private String getTipoString() {
- String tipo;
- switch (listaEnlazadaTipos.getTipo()) {
- case ListaEnlazadaTipos.SIMPLE:
- tipo = "Simple";
- break;
- case ListaEnlazadaTipos.CIRCULAR:
- tipo = "Circular";
- break;
- case ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA:
- tipo = "Doble";
- break;
- default:
- tipo = "Simple";
- }
- return tipo;
- }
-
- /**
- * Eliminar un valor de la lista si existe y mostrar el codigo en la pantalla.
- */
- @FXML
- protected void botonEliminar() {
- if (scene == null) {
- initializeLista();
- }
-
- String tipo = getTipoString();
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/listaEnlazada" + tipo + "/eliminar")).useDelimiter("\\Z").next();
- codigoLista.setText(codigoTexto);
-
- try {
- if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) {
- boolean exito;
- if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
- exito = listaEnlazada.eliminar(Integer.valueOf(valorLista.getText()));
- }
- else {
- exito = listaEnlazadaCircular.eliminar(Integer.valueOf(valorLista.getText()));
- }
- if (exito) {
- valorLista.setText("");
- generarGrafico();
- }
- else {
- Main.mostrarError(resourceBundle.getString("listaNoEsta"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
- }
- }
-
- /**
- * Buscar si existe una llave en la lista y mostrar el codigo en la pantalla
- * Si existe la llave destacarla.
- */
- @FXML
- protected void botonBuscar() {
- if (scene == null) {
- initializeLista();
- }
-
- String tipo = getTipoString();
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/listaEnlazada" + tipo + "/buscar")).useDelimiter("\\Z").next();
- codigoLista.setText(codigoTexto);
-
- try {
- if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) {
- Enlace enlace;
- if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
- enlace = listaEnlazada.buscar(Integer.valueOf(valorLista.getText()));
- }
- else {
- enlace = listaEnlazadaCircular.buscar(Integer.valueOf(valorLista.getText()));
- }
- if (enlace != null) {
- generarGrafico();
- grafico = new Grafico(scene);
- grafico.destacar("#caja_" + enlace.getLlave(), Grafico.RECTANGULO);
- grafico.destacar("#texto_" + enlace.getLlave(), Grafico.TEXTO);
- }
- else {
- Main.mostrarError(resourceBundle.getString("listaNoEsta"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
+ if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) {
+ try {
+ boolean exito;
+ if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
+ exito = listaEnlazada.insertar(Integer.valueOf(valorLista.getText()));
+ }
+ else {
+ exito = listaEnlazadaCircular.insertar(Integer.valueOf(valorLista.getText()));
+ }
+ if (exito) {
+ valorLista.setText("");
+ generarGrafico();
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("listaLlaveExiste"), resourceBundle);
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
}
}
+
+ /**
+ * Eliminar un valor de la lista si existe y mostrar el codigo en la pantalla.
+ */
+ @FXML
+ protected void botonEliminar() {
+ if (scene == null) {
+ initializeLista();
+ }
+
+ String tipo = getTipoString();
+
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/listaEnlazada" + tipo + "/eliminar")).useDelimiter("\\Z").next();
+ codigoLista.setText(codigoTexto);
+
+ try {
+ if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) {
+ boolean exito;
+ if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
+ exito = listaEnlazada.eliminar(Integer.valueOf(valorLista.getText()));
+ }
+ else {
+ exito = listaEnlazadaCircular.eliminar(Integer.valueOf(valorLista.getText()));
+ }
+ if (exito) {
+ valorLista.setText("");
+ generarGrafico();
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("listaNoEsta"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
+ }
+ }
+
+ /**
+ * Buscar si existe una llave en la lista y mostrar el codigo en la pantalla
+ * Si existe la llave destacarla.
+ */
+ @FXML
+ protected void botonBuscar() {
+ if (scene == null) {
+ initializeLista();
+ }
+
+ String tipo = getTipoString();
+
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/listaEnlazada" + tipo + "/buscar")).useDelimiter("\\Z").next();
+ codigoLista.setText(codigoTexto);
+
+ try {
+ if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) {
+ Enlace enlace;
+ if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
+ enlace = listaEnlazada.buscar(Integer.valueOf(valorLista.getText()));
+ }
+ else {
+ enlace = listaEnlazadaCircular.buscar(Integer.valueOf(valorLista.getText()));
+ }
+ if (enlace != null) {
+ generarGrafico();
+ grafico = new Grafico(scene);
+ grafico.destacar("#caja_" + enlace.getLlave(), Grafico.RECTANGULO);
+ grafico.destacar("#texto_" + enlace.getLlave(), Grafico.TEXTO);
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("listaNoEsta"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle);
+ }
+ }
+
+ /**
+ * Crear una lista vacia.
+ */
+ private void initializeLista() {
+ scene = contenidoLista.getScene();
+ grafico = new Grafico(scene);
+ listaEnlazadaTipos = (ListaEnlazadaTipos) scene.getUserData();
+ nuevaLista();
+ }
+
+ private String getTipoString() {
+ String tipo;
+ switch (listaEnlazadaTipos.getTipo()) {
+ case ListaEnlazadaTipos.SIMPLE:
+ tipo = "Simple";
+ break;
+ case ListaEnlazadaTipos.CIRCULAR:
+ tipo = "Circular";
+ break;
+ case ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA:
+ tipo = "Doble";
+ break;
+ default:
+ tipo = "Simple";
+ }
+ return tipo;
+ }
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ grafico.removerDestacar();
+ colores = new Colores();
+ contenidoLista.getChildren().clear();
+ contenidoListaCircular.getChildren().clear();
+
+ if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
+ for (int i = 0; i < listaEnlazada.size(); i++) {
+ Enlace enlace = listaEnlazada.getIndice(i);
+ if (listaEnlazada.getTipo() == ListaEnlazadaTipos.SIMPLE) {
+ dibujarSimple(enlace, false);
+ }
+ else if (listaEnlazada.getTipo() == ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA) {
+ if (i != listaEnlazada.size() - 1) {
+ dibujarDoble(enlace, (i == 0));
+ }
+ else {
+ dibujarSimple(enlace, false);
+ }
+ }
+ colores.siguinteColor();
+ }
+ }
+ else {
+ for (int i = 0; i < listaEnlazadaCircular.size(); i++) {
+ Enlace enlace = listaEnlazadaCircular.getIndice(i);
+ dibujarSimple(enlace, (i == listaEnlazadaCircular.size() - 1));
+ colores.siguinteColor();
+ }
+ if (listaEnlazadaCircular.size() > 0) {
+ contenidoListaCircular.getChildren().addAll(Grafico.crearLineaCircular(listaEnlazadaCircular.size()));
+ }
+ }
+ }
+
+ /**
+ * Crear una nueva lista enlazada.
+ */
+ private void nuevaLista() {
+ if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) {
+ listaEnlazada = new ListaEnlazada();
+ listaEnlazada.setTipo(listaEnlazadaTipos.getTipo());
+ }
+ else {
+ listaEnlazadaCircular = new ListaEnlazadaCircular();
+ listaEnlazadaCircular.setTipo(ListaEnlazadaTipos.SIMPLE);
+ }
+ }
+
+ /**
+ * Dibujarlo con una flecha.
+ *
+ * @param enlace Enlace: El enlace que tiene la llave y valor.
+ * @param sinFlecha boolean: Verdad si necesita dibujar una flecha.
+ */
+ private void dibujarSimple(Enlace enlace, boolean sinFlecha) {
+ contenidoLista.getChildren().addAll(
+ Grafico.crearCaja(colores, String.valueOf(enlace.getLlave()), String.valueOf(enlace.getLlave()))
+ );
+ if (! sinFlecha) {
+ contenidoLista.getChildren().addAll(
+ Grafico.crearLineaVertical(),
+ Grafico.crearFlechaAbajo()
+ );
+ }
+ }
+
+ /**
+ * Dibujarlo con dos flechas.
+ *
+ * @param enlace Enlace: El enlace 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) {
+ if (primer) {
+ contenidoLista.getChildren().addAll(
+ Grafico.crearFlechaArriba(),
+ Grafico.crearLineaVertical()
+ );
+ }
+ contenidoLista.getChildren().addAll(
+ Grafico.crearCaja(colores, String.valueOf(enlace.getLlave()), String.valueOf(enlace.getLlave())),
+ Grafico.crearFlechaArriba(),
+ Grafico.crearLineaVertical(),
+ Grafico.crearFlechaAbajo()
+ );
+ }
}
diff --git a/src/cl/cromer/estructuras/Main.java b/src/cl/cromer/estructuras/Main.java
index 0ac3ef8..709503e 100644
--- a/src/cl/cromer/estructuras/Main.java
+++ b/src/cl/cromer/estructuras/Main.java
@@ -30,6 +30,36 @@ public class Main extends Application {
*/
static final public boolean DEBUG = false;
+ /**
+ * Crear el stage y la scene para la aplicación grafica.
+ *
+ * @param stage Stage: El primer stage donde va todas las cosas visuales.
+ */
+ @Override
+ public void start(Stage stage) {
+ Locale locale = new Locale("es", "ES");
+ ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale);
+
+ try {
+ Parent parent = FXMLLoader.load(getClass().getResource("/cl/cromer/estructuras/fxml/main.fxml"), ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale));
+ stage.setTitle(resourceBundle.getString("titulo"));
+ Scene scene = new Scene(parent, 1024, 768);
+ scene.getStylesheets().add("/cl/cromer/estructuras/css/main.css");
+ stage.setScene(scene);
+ }
+ 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.");
+ stage.close();
+ }
+
+ //stage.setMaximized(true);
+ stage.setMinHeight(640);
+ stage.setMinWidth(768);
+ stage.getIcons().add(new Image(getClass().getResourceAsStream("/cl/cromer/estructuras/images/icon.png")));
+ stage.show();
+ }
+
/**
* Inicilizar el logeo y lanzar la interfaz grafica.
*
@@ -43,6 +73,17 @@ public class Main extends Application {
launch(args);
}
+ /**
+ * Cambiar el icono de una ventana.
+ *
+ * @param dialog Dialog: El Dialog a cambiar.
+ * @param clase Class: La clase usado para abrir el Stream.
+ */
+ static public void setIcon(Dialog dialog, Class clase) {
+ Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
+ stage.getIcons().add(new Image(clase.getResourceAsStream("/cl/cromer/estructuras/images/icon.png")));
+ }
+
/**
* Mostrar una ventana con mensaje en la pantalla.
*
@@ -59,45 +100,4 @@ public class Main extends Application {
Main.setIcon(dialog, Main.class);
dialog.show();
}
-
- /**
- * Cambiar el icono de una ventana.
- *
- * @param dialog Dialog: El Dialog a cambiar.
- * @param clase Class: La clase usado para abrir el Stream.
- */
- static public void setIcon(Dialog dialog, Class clase) {
- Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
- stage.getIcons().add(new Image(clase.getResourceAsStream("/cl/cromer/estructuras/images/icon.png")));
- }
-
- /**
- * Crear el stage y la scene para la aplicación grafica.
- *
- * @param stage Stage: El primer stage donde va todas las cosas visuales.
- */
- @Override
- public void start(Stage stage) {
- Locale locale = new Locale("es", "ES");
- ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale);
-
- try {
- Parent parent = FXMLLoader.load(getClass().getResource("/cl/cromer/estructuras/fxml/main.fxml"), ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale));
- stage.setTitle(resourceBundle.getString("titulo"));
- Scene scene = new Scene(parent, 1024, 768);
- scene.getStylesheets().add("/cl/cromer/estructuras/css/style.css");
- stage.setScene(scene);
- }
- 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.");
- stage.close();
- }
-
- //stage.setMaximized(true);
- stage.setMinHeight(640);
- stage.setMinWidth(768);
- stage.getIcons().add(new Image(getClass().getResourceAsStream("/cl/cromer/estructuras/images/icon.png")));
- stage.show();
- }
}
\ No newline at end of file
diff --git a/src/cl/cromer/estructuras/MenuController.java b/src/cl/cromer/estructuras/MenuController.java
index 672759b..1a468c4 100644
--- a/src/cl/cromer/estructuras/MenuController.java
+++ b/src/cl/cromer/estructuras/MenuController.java
@@ -56,43 +56,11 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloArraySimple"),
"/cl/cromer/estructuras/fxml/array.fxml",
- "/cl/cromer/estructuras/css/style.css",
+ "/cl/cromer/estructuras/css/main.css",
arrayTipos
);
}
- /**
- * Cargar el fxml, css y titulo.
- *
- * @param title String: El titulo de la escena.
- * @param fxml String: El archivo de fxml.
- * @param css String: El archivo de css.
- * @param object Object: El objeto a pasar a la nueva escena.
- */
- private void loadStage(String title, String fxml, String css, Object object) {
- Scene scene = menuBar.getScene();
- Stage stage = (Stage) scene.getWindow();
-
- openFXML(fxml, scene, stage);
-
- scene.getStylesheets().add(css);
- scene.setUserData(object);
- stage.setScene(scene);
- stage.setTitle(this.resourceBundle.getString("titulo") + " - " + title);
- }
-
- private void openFXML(String fxml, Scene scene, Stage stage) {
- try {
- Parent parent = FXMLLoader.load(getClass().getResource(fxml), this.resourceBundle);
- scene.setRoot(parent);
- }
- 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.");
- stage.close();
- }
- }
-
/**
* Click en Array Ordenado.
*/
@@ -102,7 +70,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloArrayOrdenado"),
"/cl/cromer/estructuras/fxml/array.fxml",
- "/cl/cromer/estructuras/css/style.css",
+ "/cl/cromer/estructuras/css/main.css",
arrayTipos
);
}
@@ -115,28 +83,10 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloBurbuja"),
"/cl/cromer/estructuras/fxml/burbuja.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
- /**
- * Cargar el fxml, css y titulo.
- *
- * @param title String: El titulo de la escena.
- * @param fxml String: El archivo de fxml.
- * @param css String: El archivo de css.
- */
- private void loadStage(String title, String fxml, String css) {
- Scene scene = menuBar.getScene();
- Stage stage = (Stage) scene.getWindow();
-
- openFXML(fxml, scene, stage);
-
- scene.getStylesheets().add(css);
- stage.setScene(scene);
- stage.setTitle(this.resourceBundle.getString("titulo") + " - " + title);
- }
-
/**
* Click en Inserción.
*/
@@ -145,7 +95,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloInsercion"),
"/cl/cromer/estructuras/fxml/insercion.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -157,7 +107,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloSeleccion"),
"/cl/cromer/estructuras/fxml/seleccion.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -169,7 +119,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloShell"),
"/cl/cromer/estructuras/fxml/shell.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -181,7 +131,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloQuick"),
"/cl/cromer/estructuras/fxml/quick.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -193,7 +143,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloMerge"),
"/cl/cromer/estructuras/fxml/merge.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -206,7 +156,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloListaEnlazadaSimple"),
"/cl/cromer/estructuras/fxml/listaEnlazada.fxml",
- "/cl/cromer/estructuras/css/style.css",
+ "/cl/cromer/estructuras/css/main.css",
listaEnlazadaTipos
);
}
@@ -220,7 +170,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloListaEnlazadaCircular"),
"/cl/cromer/estructuras/fxml/listaEnlazada.fxml",
- "/cl/cromer/estructuras/css/style.css",
+ "/cl/cromer/estructuras/css/main.css",
listaEnlazadaTipos
);
}
@@ -234,7 +184,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloListaEnlazadaDoble"),
"/cl/cromer/estructuras/fxml/listaEnlazada.fxml",
- "/cl/cromer/estructuras/css/style.css",
+ "/cl/cromer/estructuras/css/main.css",
listaEnlazadaTipos
);
}
@@ -247,7 +197,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloPila"),
"/cl/cromer/estructuras/fxml/pila.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -259,7 +209,7 @@ public class MenuController extends VBox implements Initializable {
loadStage(
resourceBundle.getString("tituloCola"),
"/cl/cromer/estructuras/fxml/cola.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -270,8 +220,8 @@ public class MenuController extends VBox implements Initializable {
protected void menuHashTable() {
loadStage(
resourceBundle.getString("tituloTablaHash"),
- "/cl/cromer/estructuras/fxml/hashTable.fxml",
- "/cl/cromer/estructuras/css/style.css"
+ "/cl/cromer/estructuras/fxml/tablaHash.fxml",
+ "/cl/cromer/estructuras/css/main.css"
);
}
@@ -296,40 +246,10 @@ public class MenuController extends VBox implements Initializable {
Locale locale = new Locale("en", "EN");
ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale);
- loadStage(
- "/cl/cromer/estructuras/fxml/main.fxml",
- "/cl/cromer/estructuras/css/style.css",
- resourceBundle
- );
+ loadStage(resourceBundle);
}
}
- /**
- * Cargar el fxml y css.
- *
- * @param fxml String: El archivo de fxml.
- * @param css String: El archivo de css.
- * @param resourceBundle ResourceBundle: El idioma nuevo para cambiarlo.
- */
- private void loadStage(String fxml, String css, ResourceBundle resourceBundle) {
- Scene scene = menuBar.getScene();
- Stage stage = (Stage) scene.getWindow();
-
- try {
- Parent parent = FXMLLoader.load(getClass().getResource(fxml), resourceBundle);
- scene.setRoot(parent);
- }
- 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.");
- stage.close();
- }
-
- scene.getStylesheets().add(css);
- stage.setScene(scene);
- stage.setTitle(resourceBundle.getString("titulo"));
- }
-
/**
* Click en Español.
*/
@@ -351,11 +271,7 @@ public class MenuController extends VBox implements Initializable {
Locale locale = new Locale("es", "ES");
ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale);
- loadStage(
- "/cl/cromer/estructuras/fxml/main.fxml",
- "/cl/cromer/estructuras/css/style.css",
- resourceBundle
- );
+ loadStage(resourceBundle);
}
}
@@ -373,4 +289,78 @@ public class MenuController extends VBox implements Initializable {
Main.setIcon(dialog, getClass());
dialog.show();
}
+
+ /**
+ * Cargar el fxml, css y titulo.
+ *
+ * @param title String: El titulo de la escena.
+ * @param fxml String: El archivo de fxml.
+ * @param css String: El archivo de css.
+ */
+ private void loadStage(String title, String fxml, String css) {
+ Scene scene = menuBar.getScene();
+ Stage stage = (Stage) scene.getWindow();
+
+ openFXML(fxml, scene, stage);
+
+ scene.getStylesheets().add(css);
+ stage.setScene(scene);
+ stage.setTitle(this.resourceBundle.getString("titulo") + " - " + title);
+ }
+
+ /**
+ * Cargar el fxml, css y titulo y pasar un objeto a la escena nueva.
+ *
+ * @param title String: El titulo de la escena.
+ * @param fxml String: El archivo de fxml.
+ * @param css String: El archivo de css.
+ * @param object Object: El objeto a pasar a la nueva escena.
+ */
+ private void loadStage(String title, String fxml, String css, Object object) {
+ Scene scene = menuBar.getScene();
+ Stage stage = (Stage) scene.getWindow();
+
+ openFXML(fxml, scene, stage);
+
+ scene.getStylesheets().add(css);
+ scene.setUserData(object);
+ stage.setScene(scene);
+ stage.setTitle(this.resourceBundle.getString("titulo") + " - " + title);
+ }
+
+ /**
+ * Cargar el fxml y css cuando el idioma cambia.
+ *
+ * @param resourceBundle ResourceBundle: El idioma nuevo para cambiarlo.
+ */
+ private void loadStage(ResourceBundle resourceBundle) {
+ Scene scene = menuBar.getScene();
+ Stage stage = (Stage) scene.getWindow();
+
+ try {
+ Parent parent = FXMLLoader.load(getClass().getResource("/cl/cromer/estructuras/fxml/main.fxml"), resourceBundle);
+ scene.setRoot(parent);
+ }
+ 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.");
+ stage.close();
+ }
+
+ scene.getStylesheets().add("/cl/cromer/estructuras/css/main.css");
+ stage.setScene(scene);
+ stage.setTitle(resourceBundle.getString("titulo"));
+ }
+
+ private void openFXML(String fxml, Scene scene, Stage stage) {
+ try {
+ Parent parent = FXMLLoader.load(getClass().getResource(fxml), this.resourceBundle);
+ scene.setRoot(parent);
+ }
+ 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.");
+ stage.close();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/cl/cromer/estructuras/MergeController.java b/src/cl/cromer/estructuras/MergeController.java
index 776205b..ccb1738 100644
--- a/src/cl/cromer/estructuras/MergeController.java
+++ b/src/cl/cromer/estructuras/MergeController.java
@@ -16,126 +16,126 @@ import java.util.Scanner;
* @author Chris Cromer
*/
public class MergeController implements Initializable {
- /**
- * Donde poner el contenido de array.
- */
- @FXML
- private HBox contenidoMerge;
+ /**
+ * Donde poner el contenido de array.
+ */
+ @FXML
+ private HBox contenidoMerge;
- /**
- * Donde va el codigo a mostrar a la pantalla.
- */
- @FXML
- private Text codigoMerge;
+ /**
+ * Donde va el codigo a mostrar a la pantalla.
+ */
+ @FXML
+ private Text codigoMerge;
- /**
- * La escena donde está cosas graficas.
- */
- private Scene scene;
+ /**
+ * La escena donde está cosas graficas.
+ */
+ private Scene scene;
- /**
- * Donde está guardado los idiomas.
- */
- private ResourceBundle resourceBundle;
+ /**
+ * Donde está guardado los idiomas.
+ */
+ private ResourceBundle resourceBundle;
- /**
- * El array usado en la aplicación.
- */
- private Array array;
+ /**
+ * El array usado en la aplicación.
+ */
+ private Array array;
- /**
- * 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
- @SuppressWarnings("Duplicates")
- public void initialize(URL location, ResourceBundle resourceBundle) {
- this.resourceBundle = resourceBundle;
+ /**
+ * 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
+ @SuppressWarnings("Duplicates")
+ public void initialize(URL location, ResourceBundle resourceBundle) {
+ this.resourceBundle = resourceBundle;
- scene = null;
+ scene = null;
- Colores colores = new Colores();
+ Colores colores = new Colores();
- array = new Array(10);
- array.setOrdered(true);
- array.llenar();
+ array = new Array(10);
+ array.setOrdered(true);
+ array.llenar();
- for (int i = 0; i < 10; i++) {
- contenidoMerge.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
- colores.siguinteColor();
- }
- }
+ for (int i = 0; i < 10; i++) {
+ contenidoMerge.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
+ colores.siguinteColor();
+ }
+ }
- /**
- * Crear un array nuevo.
- */
- @FXML
- protected void botonNuevo() {
- if (scene == null) {
- initializeScene();
- }
+ /**
+ * Crear un array nuevo.
+ */
+ @FXML
+ protected void botonNuevo() {
+ if (scene == null) {
+ initializeScene();
+ }
- array.nuevo();
- array.llenar();
- generarGrafico();
- }
+ array.nuevo();
+ array.llenar();
+ generarGrafico();
+ }
- /**
- * Crear el array de tamaño 10.
- */
- private void initializeScene() {
- scene = contenidoMerge.getScene();
- }
+ /**
+ * Ordenarlo paso por paso.
+ */
+ @FXML
+ protected void botonPaso() {
+ if (scene == null) {
+ initializeScene();
+ }
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(array.getIndice(i));
- }
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/merge/ordenar")).useDelimiter("\\Z").next();
+ codigoMerge.setText(codigoTexto);
- /**
- * Ordenarlo paso por paso.
- */
- @FXML
- protected void botonPaso() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/merge/ordenar")).useDelimiter("\\Z").next();
- codigoMerge.setText(codigoTexto);
-
- if (! array.merge(true)) {
- Main.mostrarError(resourceBundle.getString("mergeYaOrdenado"), resourceBundle);
- }
-
- generarGrafico();
- }
-
- /**
- * Ordenarlo completamente.
- */
- @FXML
- protected void botonCorrer() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/merge/ordenar")).useDelimiter("\\Z").next();
- codigoMerge.setText(codigoTexto);
-
- if (! array.merge(false)) {
- Main.mostrarError(resourceBundle.getString("mergeYaOrdenado"), resourceBundle);
- }
+ if (! array.merge(true)) {
+ Main.mostrarError(resourceBundle.getString("mergeYaOrdenado"), resourceBundle);
+ }
generarGrafico();
- }
+ }
+
+ /**
+ * Ordenarlo completamente.
+ */
+ @FXML
+ protected void botonCorrer() {
+ if (scene == null) {
+ initializeScene();
+ }
+
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/merge/ordenar")).useDelimiter("\\Z").next();
+ codigoMerge.setText(codigoTexto);
+
+ if (! array.merge(false)) {
+ Main.mostrarError(resourceBundle.getString("mergeYaOrdenado"), resourceBundle);
+ }
+
+ generarGrafico();
+ }
+
+ /**
+ * Crear el array de tamaño 10.
+ */
+ private void initializeScene() {
+ scene = contenidoMerge.getScene();
+ }
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(array.getIndice(i));
+ }
+ }
}
diff --git a/src/cl/cromer/estructuras/Pila.java b/src/cl/cromer/estructuras/Pila.java
index 9a6aa18..1da9aef 100644
--- a/src/cl/cromer/estructuras/Pila.java
+++ b/src/cl/cromer/estructuras/Pila.java
@@ -26,6 +26,30 @@ final public class Pila {
size = 0;
}
+ /**
+ * Push un valor en la pila encima.
+ *
+ * @param valor int: El valor a push.
+ */
+ public void push(int valor) {
+ if (this.pila != null) {
+ String pila[] = new String[this.pila.length + 1];
+ int i;
+ for (i = 0; i < this.pila.length; i++) {
+ pila[i] = this.pila[i];
+ }
+ pila[i] = String.valueOf(valor);
+ this.pila = pila;
+ size++;
+ }
+ else {
+ String pila[] = new String[1];
+ pila[0] = String.valueOf(valor);
+ this.pila = pila;
+ size++;
+ }
+ }
+
/**
* Pop un valor de encima de la pila.
*
@@ -44,15 +68,6 @@ final public class Pila {
}
}
- /**
- * Devolver la cantidad de elementos en la pila.
- *
- * @return int: La cantidad de elementos.
- */
- public int size() {
- return size;
- }
-
/**
* Peek al valor que está encima de la pila.
*
@@ -67,6 +82,15 @@ final public class Pila {
}
}
+ /**
+ * Devolver la cantidad de elementos en la pila.
+ *
+ * @return int: La cantidad de elementos.
+ */
+ public int size() {
+ return size;
+ }
+
/**
* Devolver el valor que está en un indice de la pila.
*
@@ -98,28 +122,4 @@ final public class Pila {
push(numero);
}
}
-
- /**
- * Push un valor en la pila encima.
- *
- * @param valor int: El valor a push.
- */
- public void push(int valor) {
- if (this.pila != null) {
- String pila[] = new String[this.pila.length + 1];
- int i;
- for (i = 0; i < this.pila.length; i++) {
- pila[i] = this.pila[i];
- }
- pila[i] = String.valueOf(valor);
- this.pila = pila;
- size++;
- }
- else {
- String pila[] = new String[1];
- pila[0] = String.valueOf(valor);
- this.pila = pila;
- size++;
- }
- }
}
\ No newline at end of file
diff --git a/src/cl/cromer/estructuras/PilaController.java b/src/cl/cromer/estructuras/PilaController.java
index 0f60311..9d60bcf 100644
--- a/src/cl/cromer/estructuras/PilaController.java
+++ b/src/cl/cromer/estructuras/PilaController.java
@@ -90,17 +90,6 @@ public class PilaController implements Initializable {
generarGrafico();
}
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- grafico.removerDestacar();
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(pila.getIndice(i));
- }
- }
-
/**
* Vaciar la pila de todos los valores.
*/
@@ -203,4 +192,15 @@ public class PilaController implements Initializable {
Main.mostrarError(resourceBundle.getString("pilaVacia"), resourceBundle);
}
}
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ grafico.removerDestacar();
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(pila.getIndice(i));
+ }
+ }
}
\ No newline at end of file
diff --git a/src/cl/cromer/estructuras/QuickController.java b/src/cl/cromer/estructuras/QuickController.java
index 2685e7b..9b1db8f 100644
--- a/src/cl/cromer/estructuras/QuickController.java
+++ b/src/cl/cromer/estructuras/QuickController.java
@@ -16,126 +16,126 @@ import java.util.Scanner;
* @author Chris Cromer
*/
public class QuickController implements Initializable {
- /**
- * Donde poner el contenido de array.
- */
- @FXML
- private HBox contenidoQuick;
+ /**
+ * Donde poner el contenido de array.
+ */
+ @FXML
+ private HBox contenidoQuick;
- /**
- * Donde va el codigo a mostrar a la pantalla.
- */
- @FXML
- private Text codigoQuick;
+ /**
+ * Donde va el codigo a mostrar a la pantalla.
+ */
+ @FXML
+ private Text codigoQuick;
- /**
- * La escena donde está cosas graficas.
- */
- private Scene scene;
+ /**
+ * La escena donde está cosas graficas.
+ */
+ private Scene scene;
- /**
- * Donde está guardado los idiomas.
- */
- private ResourceBundle resourceBundle;
+ /**
+ * Donde está guardado los idiomas.
+ */
+ private ResourceBundle resourceBundle;
- /**
- * El array usado en la aplicación.
- */
- private Array array;
+ /**
+ * El array usado en la aplicación.
+ */
+ private Array array;
- /**
- * 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
- @SuppressWarnings("Duplicates")
- public void initialize(URL location, ResourceBundle resourceBundle) {
- this.resourceBundle = resourceBundle;
+ /**
+ * 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
+ @SuppressWarnings("Duplicates")
+ public void initialize(URL location, ResourceBundle resourceBundle) {
+ this.resourceBundle = resourceBundle;
- scene = null;
+ scene = null;
- Colores colores = new Colores();
+ Colores colores = new Colores();
- array = new Array(10);
- array.setOrdered(true);
- array.llenar();
+ array = new Array(10);
+ array.setOrdered(true);
+ array.llenar();
- for (int i = 0; i < 10; i++) {
- contenidoQuick.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
- colores.siguinteColor();
- }
- }
+ for (int i = 0; i < 10; i++) {
+ contenidoQuick.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i))));
+ colores.siguinteColor();
+ }
+ }
- /**
- * Crear un array nuevo.
- */
- @FXML
- protected void botonNuevo() {
- if (scene == null) {
- initializeScene();
- }
+ /**
+ * Crear un array nuevo.
+ */
+ @FXML
+ protected void botonNuevo() {
+ if (scene == null) {
+ initializeScene();
+ }
- array.nuevo();
- array.llenar();
- generarGrafico();
- }
+ array.nuevo();
+ array.llenar();
+ generarGrafico();
+ }
- /**
- * Crear el array de tamaño 10.
- */
- private void initializeScene() {
- scene = contenidoQuick.getScene();
- }
+ /**
+ * Ordenarlo paso por paso.
+ */
+ @FXML
+ protected void botonPaso() {
+ if (scene == null) {
+ initializeScene();
+ }
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(array.getIndice(i));
- }
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/quick/ordenar")).useDelimiter("\\Z").next();
+ codigoQuick.setText(codigoTexto);
- /**
- * Ordenarlo paso por paso.
- */
- @FXML
- protected void botonPaso() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/quick/ordenar")).useDelimiter("\\Z").next();
- codigoQuick.setText(codigoTexto);
-
- if (! array.quick(true)) {
- Main.mostrarError(resourceBundle.getString("quickYaOrdenado"), resourceBundle);
- }
-
- generarGrafico();
- }
-
- /**
- * Ordenarlo completamente.
- */
- @FXML
- protected void botonCorrer() {
- if (scene == null) {
- initializeScene();
- }
-
- // Mostrar el codigo
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/quick/ordenar")).useDelimiter("\\Z").next();
- codigoQuick.setText(codigoTexto);
-
- if (! array.quick(false)) {
- Main.mostrarError(resourceBundle.getString("quickYaOrdenado"), resourceBundle);
- }
+ if (! array.quick(true)) {
+ Main.mostrarError(resourceBundle.getString("quickYaOrdenado"), resourceBundle);
+ }
generarGrafico();
- }
+ }
+
+ /**
+ * Ordenarlo completamente.
+ */
+ @FXML
+ protected void botonCorrer() {
+ if (scene == null) {
+ initializeScene();
+ }
+
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/quick/ordenar")).useDelimiter("\\Z").next();
+ codigoQuick.setText(codigoTexto);
+
+ if (! array.quick(false)) {
+ Main.mostrarError(resourceBundle.getString("quickYaOrdenado"), resourceBundle);
+ }
+
+ generarGrafico();
+ }
+
+ /**
+ * Crear el array de tamaño 10.
+ */
+ private void initializeScene() {
+ scene = contenidoQuick.getScene();
+ }
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(array.getIndice(i));
+ }
+ }
}
diff --git a/src/cl/cromer/estructuras/SeleccionController.java b/src/cl/cromer/estructuras/SeleccionController.java
index 2b06a65..51a91ae 100644
--- a/src/cl/cromer/estructuras/SeleccionController.java
+++ b/src/cl/cromer/estructuras/SeleccionController.java
@@ -82,23 +82,6 @@ public class SeleccionController implements Initializable {
generarGrafico();
}
- /**
- * Crear el array de tamaño 10.
- */
- private void initializeScene() {
- scene = contenidoSeleccion.getScene();
- }
-
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(array.getIndice(i));
- }
- }
-
/**
* Ordenarlo paso por paso.
*/
@@ -138,4 +121,21 @@ public class SeleccionController implements Initializable {
generarGrafico();
}
+
+ /**
+ * Crear el array de tamaño 10.
+ */
+ private void initializeScene() {
+ scene = contenidoSeleccion.getScene();
+ }
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(array.getIndice(i));
+ }
+ }
}
diff --git a/src/cl/cromer/estructuras/ShellController.java b/src/cl/cromer/estructuras/ShellController.java
index 3cf279c..2cfc53f 100644
--- a/src/cl/cromer/estructuras/ShellController.java
+++ b/src/cl/cromer/estructuras/ShellController.java
@@ -82,23 +82,6 @@ public class ShellController implements Initializable {
generarGrafico();
}
- /**
- * Crear el array de tamaño 10.
- */
- private void initializeScene() {
- scene = contenidoShell.getScene();
- }
-
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- for (int i = 0; i < 10; i++) {
- Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
- text.setText(array.getIndice(i));
- }
- }
-
/**
* Ordenarlo paso por paso.
*/
@@ -138,4 +121,21 @@ public class ShellController implements Initializable {
generarGrafico();
}
+
+ /**
+ * Crear el array de tamaño 10.
+ */
+ private void initializeScene() {
+ scene = contenidoShell.getScene();
+ }
+
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ for (int i = 0; i < 10; i++) {
+ Text text = (Text) scene.lookup("#texto_" + String.valueOf(i));
+ text.setText(array.getIndice(i));
+ }
+ }
}
diff --git a/src/cl/cromer/estructuras/TablaHash.java b/src/cl/cromer/estructuras/TablaHash.java
index fbb9050..e0385c5 100644
--- a/src/cl/cromer/estructuras/TablaHash.java
+++ b/src/cl/cromer/estructuras/TablaHash.java
@@ -31,15 +31,6 @@ public class TablaHash {
hashArray = new HashItem[tamano];
}
- /**
- * Devolver la cantidad de elementos que están en la tabla.
- *
- * @return int: La cantidad.
- */
- public int size() {
- return size;
- }
-
/**
* Este metodo crea un hash muy único.
*
@@ -47,7 +38,6 @@ public class TablaHash {
*
* @return int: El hash a devolver.
*/
- @SuppressWarnings("unused")
public int hashMejor(String string) {
int intLength = string.length() / 4;
int sum = 0;
@@ -70,6 +60,25 @@ public class TablaHash {
return (Math.abs(sum) % tamano);
}
+ /**
+ * Este metodo crea un hash usando una llave.
+ *
+ * @param string String: El string a hashear.
+ *
+ * @return int: El hash a devolver.
+ */
+ @SuppressWarnings("unused")
+ public int hash(String string) {
+ int hash = 31;
+ for (int i = 0; i < string.length(); i++) {
+ hash = hash * 31 + string.charAt(i);
+ }
+ if (hash < 0) {
+ hash = hash * - 1;
+ }
+ return hash % tamano;
+ }
+
/**
* Insertar una llave y valor en la tabla hash.
*
@@ -80,7 +89,7 @@ public class TablaHash {
*/
public boolean insertar(String llave, int valor) {
HashItem hashItem = new HashItem(llave, valor);
- int hashIndice = hash(hashItem.getLlave());
+ int hashIndice = hashMejor(hashItem.getLlave());
int i = 0;
while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) {
if (hashArray[hashIndice].getLlave().equals(llave)) {
@@ -101,24 +110,6 @@ public class TablaHash {
}
}
- /**
- * Este metodo crea un hash usando una llave.
- *
- * @param string String: El string a hashear.
- *
- * @return int: El hash a devolver.
- */
- public int hash(String string) {
- int hash = 31;
- for (int i = 0; i < string.length(); i++) {
- hash = hash * 31 + string.charAt(i);
- }
- if (hash < 0) {
- hash = hash * - 1;
- }
- return hash % tamano;
- }
-
/**
* Eliminar un elemento de la tabla hash.
*
@@ -128,7 +119,7 @@ public class TablaHash {
*/
public boolean eliminar(String llave) {
HashItem hashItem = new HashItem(llave, 0);
- int hashIndice = hash(hashItem.getLlave());
+ int hashIndice = hashMejor(hashItem.getLlave());
int i = 0;
while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) {
if (hashArray[hashIndice].getLlave().equals(llave)) {
@@ -159,6 +150,15 @@ public class TablaHash {
return null;
}
+ /**
+ * Devolver la cantidad de elementos que están en la tabla.
+ *
+ * @return int: La cantidad.
+ */
+ public int size() {
+ return size;
+ }
+
/**
* Devolver el valor que está guardado en cada indice. Se usa para construir la grafica.
*
diff --git a/src/cl/cromer/estructuras/TablaHashController.java b/src/cl/cromer/estructuras/TablaHashController.java
index e75c0f1..d0ea438 100644
--- a/src/cl/cromer/estructuras/TablaHashController.java
+++ b/src/cl/cromer/estructuras/TablaHashController.java
@@ -9,6 +9,7 @@ import javafx.scene.text.Text;
import java.net.URL;
import java.util.Random;
import java.util.ResourceBundle;
+import java.util.Scanner;
import java.util.logging.Level;
/**
@@ -17,262 +18,259 @@ import java.util.logging.Level;
* @author Chris Cromer
*/
public class TablaHashController implements Initializable {
- /**
- * La caja para ingresar la llave.
- */
- @FXML
- private TextFieldLimited llaveHashTable;
+ /**
+ * La caja para ingresar la llave.
+ */
+ @FXML
+ private TextFieldLimited llaveHashTable;
- /**
- * La caja para ingresar el valor.
- */
- @FXML
- private TextFieldLimited valorHashTable;
+ /**
+ * La caja para ingresar el valor.
+ */
+ @FXML
+ private TextFieldLimited valorHashTable;
- /**
- * Donde poner el contenido de tablaHash.
- */
- @FXML
- private VBox contenidoHashTable;
+ /**
+ * Donde poner el contenido de tablaHash.
+ */
+ @FXML
+ private VBox contenidoHashTable;
- /**
- * Donde va el codigo a mostrar a la pantalla.
- */
- @FXML
- private Text codigoHashTable;
+ /**
+ * Donde va el codigo a mostrar a la pantalla.
+ */
+ @FXML
+ private Text codigoHashTable;
- /**
- * La escena donde está cosas graficas.
- */
- private Scene scene;
+ /**
+ * La escena donde está cosas graficas.
+ */
+ private Scene scene;
- /**
- * Donde está guardado los idiomas.
- */
- private ResourceBundle resourceBundle;
+ /**
+ * Donde está guardado los idiomas.
+ */
+ private ResourceBundle resourceBundle;
- /**
- * El tablaHash usado en la aplicación.
- */
- private TablaHash tablaHash;
+ /**
+ * El tablaHash usado en la aplicación.
+ */
+ private TablaHash tablaHash;
- /**
- * Grafico rectangulos.
- */
- private Grafico grafico;
+ /**
+ * 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;
+ /**
+ * 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;
- scene = null;
- Colores colores = new Colores();
+ scene = null;
+ Colores colores = new Colores();
- for (int i = 0; i < 10; i++) {
- contenidoHashTable.getChildren().addAll(Grafico.crearHashCajas(colores, String.valueOf(i)));
- colores.siguinteColor();
- }
- }
+ for (int i = 0; i < 10; i++) {
+ contenidoHashTable.getChildren().addAll(Grafico.crearHashCajas(colores, String.valueOf(i)));
+ colores.siguinteColor();
+ }
+ }
- /**
- * Llenar el tablaHash con numeros al azar.
- */
- @FXML
- protected void botonLlenar() {
- if (scene == null) {
- initializeHashTable();
- }
+ /**
+ * Llenar el tablaHash con numeros al azar.
+ */
+ @FXML
+ protected void botonLlenar() {
+ if (scene == null) {
+ initializeHashTable();
+ }
- Palabras palabras = new Palabras();
+ Palabras palabras = new Palabras();
- Random random = new Random();
- int maximo = 99;
- int minimo = 0;
- int rango = maximo - minimo + 1;
+ Random random = new Random();
+ int maximo = 99;
+ int minimo = 0;
+ int rango = maximo - minimo + 1;
- for (int i = 0; i < 10; i++) {
- int numero = random.nextInt(rango) + minimo;
- while (! tablaHash.insertar(palabras.getPalabra(), numero)) {
- if (tablaHash.size() == 10) {
- break;
- }
- }
- }
- generarGrafico();
- }
+ for (int i = 0; i < 10; i++) {
+ int numero = random.nextInt(rango) + minimo;
+ while (! tablaHash.insertar(palabras.getPalabra(), numero)) {
+ if (tablaHash.size() == 10) {
+ break;
+ }
+ }
+ }
+ generarGrafico();
+ }
- /**
- * Crear el tablaHash de tamaño 10.
- */
- private void initializeHashTable() {
- scene = contenidoHashTable.getScene();
- grafico = new Grafico(scene);
- this.tablaHash = new TablaHash(10);
- }
+ /**
+ * Vaciar el tablaHash de todos los valores.
+ */
+ @FXML
+ protected void botonVaciar() {
+ if (scene == null) {
+ initializeHashTable();
+ }
- /**
- * Poner los valores en el grafico.
- */
- private void generarGrafico() {
- grafico.removerDestacar();
- for (int i = 0; i < 10; i++) {
- if (tablaHash.getIndice(i) != null) {
- Text text = (Text) scene.lookup("#indice_texto_" + String.valueOf(i));
- text.setText(String.valueOf(i));
- text = (Text) scene.lookup("#llave_texto_" + String.valueOf(i));
- text.setText(tablaHash.getIndice(i).getLlave());
- text = (Text) scene.lookup("#valor_texto_" + String.valueOf(i));
- text.setText(String.valueOf(tablaHash.getIndice(i).getValor()));
- }
- else {
- Text text = (Text) scene.lookup("#indice_texto_" + String.valueOf(i));
- text.setText("");
- text = (Text) scene.lookup("#llave_texto_" + String.valueOf(i));
- text.setText("");
- text = (Text) scene.lookup("#valor_texto_" + String.valueOf(i));
- text.setText("");
- }
- }
- }
+ tablaHash = new TablaHash(10);
+ generarGrafico();
+ }
- /**
- * Vaciar el tablaHash de todos los valores.
- */
- @FXML
- protected void botonVaciar() {
- if (scene == null) {
- initializeHashTable();
- }
+ /**
+ * Insertar un valor al tablaHash y mostrar el codigo en la pantalla.
+ */
+ @FXML
+ protected void botonInsertar() {
+ if (scene == null) {
+ initializeHashTable();
+ }
- tablaHash = new TablaHash(10);
- generarGrafico();
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash/insertar")).useDelimiter("\\Z").next();
+ codigoHashTable.setText(codigoTexto);
- /**
- * Insertar un valor al tablaHash y mostrar el codigo en la pantalla.
- */
- @FXML
- protected void botonInsertar() {
- if (scene == null) {
- initializeHashTable();
- }
+ if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("") && valorHashTable.getText() != null && ! valorHashTable.getText().trim().equals("")) {
+ try {
+ boolean exito = tablaHash.insertar(llaveHashTable.getText().trim(), Integer.valueOf(valorHashTable.getText()));
+ if (exito) {
+ llaveHashTable.setText("");
+ valorHashTable.setText("");
+ generarGrafico();
+ }
+ else {
+ if (tablaHash.size() == 10) {
+ Main.mostrarError(resourceBundle.getString("tablaHashLleno"), resourceBundle);
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("tablaHashLlaveExiste"), resourceBundle);
+ }
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
+ }
+ }
- // Mostrar el codigo
- /*String tipo = (tablaHash.isOrdered()) ? "Ordenado" : "Simple";
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash" + tipo + "/insertar")).useDelimiter("\\Z").next();
- codigoHashTable.setText(codigoTexto);*/
+ /**
+ * Eliminar un valor del tablaHash si existe y mostrar el codigo en la pantalla.
+ */
+ @FXML
+ protected void botonEliminar() {
+ if (scene == null) {
+ initializeHashTable();
+ }
- if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("") && valorHashTable.getText() != null && ! valorHashTable.getText().trim().equals("")) {
- try {
- boolean exito = tablaHash.insertar(llaveHashTable.getText().trim(), Integer.valueOf(valorHashTable.getText()));
- if (exito) {
- llaveHashTable.setText("");
- valorHashTable.setText("");
- generarGrafico();
- }
- else {
- if (tablaHash.size() == 10) {
- Main.mostrarError(resourceBundle.getString("tablaHashLleno"), resourceBundle);
- }
- else {
- Main.mostrarError(resourceBundle.getString("tablaHashLlaveExiste"), resourceBundle);
- }
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
- }
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash/eliminar")).useDelimiter("\\Z").next();
+ codigoHashTable.setText(codigoTexto);
- /**
- * Eliminar un valor del tablaHash si existe y mostrar el codigo en la pantalla.
- */
- @FXML
- protected void botonEliminar() {
- if (scene == null) {
- initializeHashTable();
- }
+ try {
+ if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) {
+ boolean exito = tablaHash.eliminar(llaveHashTable.getText());
+ if (exito) {
+ llaveHashTable.setText("");
+ valorHashTable.setText("");
+ generarGrafico();
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("tablaHashNoEsta"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
+ }
+ }
- // Mostrar el codigo
- /*String tipo = (tablaHash.isOrdered()) ? "Ordenado" : "Simple";
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash" + tipo + "/eliminar")).useDelimiter("\\Z").next();
- codigoHashTable.setText(codigoTexto);*/
+ /**
+ * Buscar si existe un elemento en el tablaHash y mostrar el codigo en la pantalla
+ * Si existe el valor destacarlo.
+ */
+ @FXML
+ protected void botonBuscar() {
+ if (scene == null) {
+ initializeHashTable();
+ }
- try {
- if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) {
- boolean exito = tablaHash.eliminar(llaveHashTable.getText());
- if (exito) {
- llaveHashTable.setText("");
- valorHashTable.setText("");
- generarGrafico();
- }
- else {
- Main.mostrarError(resourceBundle.getString("tablaHashNoEsta"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
- }
- }
+ // Mostrar el codigo
+ String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash/buscar")).useDelimiter("\\Z").next();
+ codigoHashTable.setText(codigoTexto);
- /**
- * Buscar si existe un elemento en el tablaHash y mostrar el codigo en la pantalla
- * Si existe el valor destacarlo.
- */
- @FXML
- protected void botonBuscar() {
- if (scene == null) {
- initializeHashTable();
- }
+ try {
+ if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) {
+ HashItem hashItem = tablaHash.buscar(llaveHashTable.getText());
+ if (hashItem != null) {
+ generarGrafico();
+ grafico = new Grafico(scene);
+ grafico.destacar("#indice_caja_" + hashItem.getIndice(), Grafico.RECTANGULO);
+ grafico.destacar("#indice_texto_" + hashItem.getIndice(), Grafico.TEXTO);
+ grafico.destacar("#llave_caja_" + hashItem.getIndice(), Grafico.RECTANGULO);
+ grafico.destacar("#llave_texto_" + hashItem.getIndice(), Grafico.TEXTO);
+ grafico.destacar("#valor_caja_" + hashItem.getIndice(), Grafico.RECTANGULO);
+ grafico.destacar("#valor_texto_" + hashItem.getIndice(), Grafico.TEXTO);
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("tablaHashNoEsta"), resourceBundle);
+ }
+ }
+ else {
+ Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
+ }
+ }
+ catch (NumberFormatException exception) {
+ // El error no es fatal, sigue
+ Logs.log(Level.WARNING, "No es tipo int.");
+ Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
+ }
+ }
- // Mostrar el codigo
- /*String tipo = (tablaHash.isOrdered()) ? "Ordenado" : "Simple";
- String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash" + tipo + "/buscar")).useDelimiter("\\Z").next();
- codigoHashTable.setText(codigoTexto);*/
+ /**
+ * Crear el tablaHash de tamaño 10.
+ */
+ private void initializeHashTable() {
+ scene = contenidoHashTable.getScene();
+ grafico = new Grafico(scene);
+ this.tablaHash = new TablaHash(10);
+ }
- try {
- if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) {
- HashItem hashItem = tablaHash.buscar(llaveHashTable.getText());
- if (hashItem != null) {
- generarGrafico();
- grafico = new Grafico(scene);
- grafico.destacar("#indice_caja_" + hashItem.getIndice(), Grafico.RECTANGULO);
- grafico.destacar("#indice_texto_" + hashItem.getIndice(), Grafico.TEXTO);
- grafico.destacar("#llave_caja_" + hashItem.getIndice(), Grafico.RECTANGULO);
- grafico.destacar("#llave_texto_" + hashItem.getIndice(), Grafico.TEXTO);
- grafico.destacar("#valor_caja_" + hashItem.getIndice(), Grafico.RECTANGULO);
- grafico.destacar("#valor_texto_" + hashItem.getIndice(), Grafico.TEXTO);
- }
- else {
- Main.mostrarError(resourceBundle.getString("tablaHashNoEsta"), resourceBundle);
- }
- }
- else {
- Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
- }
- }
- catch (NumberFormatException exception) {
- // El error no es fatal, sigue
- Logs.log(Level.WARNING, "No es tipo int.");
- Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle);
- }
+ /**
+ * Poner los valores en el grafico.
+ */
+ private void generarGrafico() {
+ grafico.removerDestacar();
+ for (int i = 0; i < 10; i++) {
+ if (tablaHash.getIndice(i) != null) {
+ Text text = (Text) scene.lookup("#indice_texto_" + String.valueOf(i));
+ text.setText(String.valueOf(i));
+ text = (Text) scene.lookup("#llave_texto_" + String.valueOf(i));
+ text.setText(tablaHash.getIndice(i).getLlave());
+ text = (Text) scene.lookup("#valor_texto_" + String.valueOf(i));
+ text.setText(String.valueOf(tablaHash.getIndice(i).getValor()));
+ }
+ else {
+ Text text = (Text) scene.lookup("#indice_texto_" + String.valueOf(i));
+ text.setText("");
+ text = (Text) scene.lookup("#llave_texto_" + String.valueOf(i));
+ text.setText("");
+ text = (Text) scene.lookup("#valor_texto_" + String.valueOf(i));
+ text.setText("");
+ }
+ }
}
}
diff --git a/src/cl/cromer/estructuras/code/tablaHash/buscar b/src/cl/cromer/estructuras/code/tablaHash/buscar
index 5a7d78e..781352b 100644
--- a/src/cl/cromer/estructuras/code/tablaHash/buscar
+++ b/src/cl/cromer/estructuras/code/tablaHash/buscar
@@ -1,3 +1,28 @@
+public HashItem buscar(String llave) {
+ for (int i = 0; i < tamano; i++) {
+ // Buscar la llave en los elementos del array.
+ if (hashArray[i] != null && hashArray[i].getLlave().equals(llave)) {
+ // Encontró la llave, devuelve el HashItem que la contiene.
+ return hashArray[i];
+ }
+ }
+ // No se encontró.
+ return null;
+}
+
+public int hash(String string) {
+ // Multiplicar por un numero primo(31) para generar mejor hashes.
+ int hash = 31;
+ for (int i = 0; i < string.length(); i++) {
+ // Suma usando cada char del string.
+ hash = hash * 31 + string.charAt(i);
+ }
+ if (hash < 0) {
+ hash = hash * - 1;
+ }
+ return hash % tamano;
+}
+
public class HashItem {
final private String llave;
final private int valor;
diff --git a/src/cl/cromer/estructuras/code/tablaHash/eliminar b/src/cl/cromer/estructuras/code/tablaHash/eliminar
index 5a7d78e..70c533a 100644
--- a/src/cl/cromer/estructuras/code/tablaHash/eliminar
+++ b/src/cl/cromer/estructuras/code/tablaHash/eliminar
@@ -1,3 +1,33 @@
+public void eliminar(String llave) {
+ HashItem hashItem = new HashItem(llave, 0);
+ int hashIndice = hash(hashItem.getLlave());
+ int i = 0;
+ // Buscar hasta que encuentra la llave.
+ while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) {
+ if (hashArray[hashIndice].getLlave().equals(llave)) {
+ // Encontró la llave, borrarla.
+ hashArray[hashIndice] = null;
+ return;
+ }
+ hashIndice++;
+ hashIndice = hashIndice % tamano;
+ i++;
+ }
+}
+
+public int hash(String string) {
+ // Multiplicar por un numero primo(31) para generar mejor hashes.
+ int hash = 31;
+ for (int i = 0; i < string.length(); i++) {
+ // Suma usando cada char del string.
+ hash = hash * 31 + string.charAt(i);
+ }
+ if (hash < 0) {
+ hash = hash * - 1;
+ }
+ return hash % tamano;
+}
+
public class HashItem {
final private String llave;
final private int valor;
diff --git a/src/cl/cromer/estructuras/code/tablaHash/insertar b/src/cl/cromer/estructuras/code/tablaHash/insertar
index 588b2e0..cb1f71f 100644
--- a/src/cl/cromer/estructuras/code/tablaHash/insertar
+++ b/src/cl/cromer/estructuras/code/tablaHash/insertar
@@ -21,6 +21,19 @@ public void insertar(String llave, int valor) {
}
}
+public int hash(String string) {
+ // Multiplicar por un numero primo(31) para generar mejor hashes.
+ int hash = 31;
+ for (int i = 0; i < string.length(); i++) {
+ // Suma usando cada char del string.
+ hash = hash * 31 + string.charAt(i);
+ }
+ if (hash < 0) {
+ hash = hash * - 1;
+ }
+ return hash % tamano;
+}
+
public class HashItem {
final private String llave;
final private int valor;
diff --git a/src/cl/cromer/estructuras/css/main.css b/src/cl/cromer/estructuras/css/main.css
new file mode 100644
index 0000000..4c81081
--- /dev/null
+++ b/src/cl/cromer/estructuras/css/main.css
@@ -0,0 +1,8 @@
+.text {
+ -fx-font-family: "Arial";
+ -fx-font-size: 14;
+}
+
+.scroll-pane {
+ -fx-background-color: transparent;
+}
\ No newline at end of file
diff --git a/src/cl/cromer/estructuras/css/style.css b/src/cl/cromer/estructuras/css/style.css
deleted file mode 100644
index 662ef59..0000000
--- a/src/cl/cromer/estructuras/css/style.css
+++ /dev/null
@@ -1,17 +0,0 @@
-.text {
- -fx-font-family: "Arial";
- -fx-font-size: 14;
-}
-
-.menu-bar {
- -fx-background-color: #aeb5ba, linear-gradient(to bottom, #ecf4fa 0%, #ced4d9 100%);
- -fx-background-insets: 0, 0 0 1 0;
-}
-
-.menu-bar .menu .label {
- -fx-text-fill: #2d3e4c;
-}
-
-.scroll-pane {
- -fx-background-color: transparent;
-}
\ No newline at end of file
diff --git a/src/cl/cromer/estructuras/fxml/hashTable.fxml b/src/cl/cromer/estructuras/fxml/tablaHash.fxml
similarity index 95%
rename from src/cl/cromer/estructuras/fxml/hashTable.fxml
rename to src/cl/cromer/estructuras/fxml/tablaHash.fxml
index 415cef2..edb1ef4 100644
--- a/src/cl/cromer/estructuras/fxml/hashTable.fxml
+++ b/src/cl/cromer/estructuras/fxml/tablaHash.fxml
@@ -18,6 +18,8 @@
+
+