From 4cc0349ffe640f398db7baafb424ad4e5461dfed Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 3 Jul 2016 11:28:26 -0400 Subject: [PATCH] Changed indentations. --- .../cromer/estructuras/ArrayController.java | 12 +- src/cl/cromer/estructuras/ArrayTipos.java | 75 ++- .../cromer/estructuras/BurbujaController.java | 8 +- src/cl/cromer/estructuras/Cola.java | 211 +++--- src/cl/cromer/estructuras/ColaController.java | 324 ++++----- src/cl/cromer/estructuras/Colores.java | 158 ++--- src/cl/cromer/estructuras/Enlace.java | 72 +- src/cl/cromer/estructuras/EnlaceCircular.java | 122 ++-- src/cl/cromer/estructuras/EnlaceNormal.java | 134 ++-- src/cl/cromer/estructuras/HashTable.java | 214 +++--- .../estructuras/HashTableController.java | 92 +-- .../estructuras/InsercionController.java | 8 +- src/cl/cromer/estructuras/ListaEnlazada.java | 320 ++++----- .../estructuras/ListaEnlazadaCircular.java | 333 ++++----- .../estructuras/ListaEnlazadaTipos.java | 90 +-- .../estructuras/ListaEnlazdaController.java | 12 +- src/cl/cromer/estructuras/Logs.java | 72 +- src/cl/cromer/estructuras/Main.java | 136 ++-- src/cl/cromer/estructuras/MenuController.java | 630 +++++++++--------- .../cromer/estructuras/MergeController.java | 8 +- src/cl/cromer/estructuras/Palabras.java | 110 +-- src/cl/cromer/estructuras/Pila.java | 209 +++--- src/cl/cromer/estructuras/PilaController.java | 324 ++++----- .../cromer/estructuras/QuickController.java | 8 +- .../estructuras/SeleccionController.java | 182 ++--- .../cromer/estructuras/ShellController.java | 182 ++--- .../cromer/estructuras/TextFieldLimited.java | 256 +++---- .../estructuras/code/arrayOrdenado/buscar | 16 +- .../estructuras/code/arrayOrdenado/eliminar | 32 +- .../estructuras/code/arrayOrdenado/insertar | 22 +- .../estructuras/code/arraySimple/buscar | 16 +- .../estructuras/code/arraySimple/eliminar | 20 +- .../estructuras/code/arraySimple/insertar | 22 +- .../cromer/estructuras/code/burbuja/ordenar | 22 +- src/cl/cromer/estructuras/code/cola/peek | 4 +- src/cl/cromer/estructuras/code/cola/pop | 8 +- src/cl/cromer/estructuras/code/cola/push | 8 +- .../cromer/estructuras/code/insercion/ordenar | 24 +- .../code/listaEnlazadaCircular/buscar | 74 +- .../code/listaEnlazadaCircular/eliminar | 92 +-- .../code/listaEnlazadaCircular/insertar | 56 +- .../code/listaEnlazadaDoble/buscar | 86 +-- .../code/listaEnlazadaDoble/eliminar | 104 +-- .../code/listaEnlazadaDoble/insertar | 64 +- .../code/listaEnlazadaSimple/buscar | 72 +- .../code/listaEnlazadaSimple/eliminar | 84 +-- .../code/listaEnlazadaSimple/insertar | 42 +- src/cl/cromer/estructuras/code/merge/ordenar | 76 +-- src/cl/cromer/estructuras/code/pila/peek | 4 +- src/cl/cromer/estructuras/code/pila/pop | 8 +- src/cl/cromer/estructuras/code/pila/push | 8 +- src/cl/cromer/estructuras/code/quick/ordenar | 72 +- .../cromer/estructuras/code/seleccion/ordenar | 22 +- src/cl/cromer/estructuras/code/shell/ordenar | 42 +- 54 files changed, 2708 insertions(+), 2694 deletions(-) diff --git a/src/cl/cromer/estructuras/ArrayController.java b/src/cl/cromer/estructuras/ArrayController.java index 637ec3f..bf136e0 100644 --- a/src/cl/cromer/estructuras/ArrayController.java +++ b/src/cl/cromer/estructuras/ArrayController.java @@ -59,7 +59,7 @@ public class ArrayController implements Initializable { /** * Inicializar todos los datos y dibujar las graficas. * - * @param location URL: El URL de fxml en uso. + * @param location URL: El URL de fxml en uso. * @param resourceBundle ResourceBundle: Tiene datos de idioma. */ @Override @@ -146,7 +146,7 @@ public class ArrayController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/array" + tipo + "/insertar")).useDelimiter("\\Z").next(); codigoArray.setText(codigoTexto); - if (valorArray.getText() != null && !valorArray.getText().trim().equals("")) { + if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) { try { boolean exito = array.insertar(Integer.valueOf(valorArray.getText())); if (exito) { @@ -188,7 +188,7 @@ public class ArrayController implements Initializable { codigoArray.setText(codigoTexto); try { - if (valorArray.getText() != null && !valorArray.getText().trim().equals("")) { + if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) { boolean exito = array.eliminar(Integer.valueOf(valorArray.getText())); if (exito) { valorArray.setText(""); @@ -225,9 +225,9 @@ public class ArrayController implements Initializable { codigoArray.setText(codigoTexto); try { - if (valorArray.getText() != null && !valorArray.getText().trim().equals("")) { + if (valorArray.getText() != null && ! valorArray.getText().trim().equals("")) { int encontrado = array.buscar(Integer.valueOf(valorArray.getText())); - if (encontrado != -1) { + if (encontrado != - 1) { generarGrafico(); grafico = new Grafico(scene); grafico.destacar("#caja_" + encontrado, Grafico.RECTANGULO); @@ -246,5 +246,5 @@ public class ArrayController implements Initializable { Logs.log(Level.WARNING, "No es tipo int."); Main.mostrarError(resourceBundle.getString("arrayNoValor"), resourceBundle); } - } + } } diff --git a/src/cl/cromer/estructuras/ArrayTipos.java b/src/cl/cromer/estructuras/ArrayTipos.java index 59fa96f..360deae 100644 --- a/src/cl/cromer/estructuras/ArrayTipos.java +++ b/src/cl/cromer/estructuras/ArrayTipos.java @@ -6,44 +6,45 @@ package cl.cromer.estructuras; * @author Chris Cromer */ final public class ArrayTipos { - /** - * Tipo de array simple. - */ - static final public int SIMPLE = 0; - /** - * Tipo de array ordenado. - */ - static final public int ORDENADO = 1; + /** + * Tipo de array simple. + */ + static final public int SIMPLE = 0; - /** - * El tipo que está elegido. - */ - final private int tipo; + /** + * Tipo de array ordenado. + */ + static final public int ORDENADO = 1; - /** - * Inicilizar el tipo. - * - * @param tipo int: Tipo de array, {@value #SIMPLE} o {@value #ORDENADO} - */ - public ArrayTipos(int tipo) { - switch (tipo) { - case SIMPLE: - this.tipo = SIMPLE; - break; - case ORDENADO: - this.tipo = ORDENADO; - break; - default: - this.tipo = SIMPLE; - } - } + /** + * El tipo que está elegido. + */ + final private int tipo; - /** - * Devolver el tipo. - * - * @return int: El tipo de array. - */ - public int getTipo() { - return tipo; - } + /** + * Inicilizar el tipo. + * + * @param tipo int: Tipo de array, {@value #SIMPLE} o {@value #ORDENADO} + */ + public ArrayTipos(int tipo) { + switch (tipo) { + case SIMPLE: + this.tipo = SIMPLE; + break; + case ORDENADO: + this.tipo = ORDENADO; + break; + default: + this.tipo = SIMPLE; + } + } + + /** + * Devolver el tipo. + * + * @return int: El tipo de array. + */ + public int getTipo() { + return tipo; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/BurbujaController.java b/src/cl/cromer/estructuras/BurbujaController.java index e0976c8..c01b95f 100644 --- a/src/cl/cromer/estructuras/BurbujaController.java +++ b/src/cl/cromer/estructuras/BurbujaController.java @@ -46,7 +46,7 @@ public class BurbujaController implements Initializable { /** * Inicializar todos los datos y dibujar las graficas. * - * @param location URL: El URL de fxml en uso. + * @param location URL: El URL de fxml en uso. * @param resourceBundle ResourceBundle: Tiene datos de idioma. */ @Override @@ -112,7 +112,7 @@ public class BurbujaController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/burbuja/ordenar")).useDelimiter("\\Z").next(); codigoBurbuja.setText(codigoTexto); - if (!array.burbuja(true)) { + if (! array.burbuja(true)) { Main.mostrarError(resourceBundle.getString("burbujaYaOrdenado"), resourceBundle); } @@ -132,10 +132,10 @@ public class BurbujaController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/burbuja/ordenar")).useDelimiter("\\Z").next(); codigoBurbuja.setText(codigoTexto); - if (!array.burbuja(false)) { + if (! array.burbuja(false)) { Main.mostrarError(resourceBundle.getString("burbujaYaOrdenado"), resourceBundle); } - generarGrafico(); + generarGrafico(); } } diff --git a/src/cl/cromer/estructuras/Cola.java b/src/cl/cromer/estructuras/Cola.java index 6123c41..538b007 100644 --- a/src/cl/cromer/estructuras/Cola.java +++ b/src/cl/cromer/estructuras/Cola.java @@ -8,118 +8,119 @@ import java.util.Random; * @author Chris Cromer */ final public class Cola { - /** - * La cola. - */ - private String cola[]; + /** + * La cola. + */ + private String cola[]; - /** - * La cantidad de elementos que están en la cola. - */ - private int size; + /** + * La cantidad de elementos que están en la cola. + */ + private int size; - /** - * Inicializar. - */ - public Cola() { - this.cola = null; - size = 0; - } + /** + * Inicializar. + */ + public Cola() { + this.cola = null; + size = 0; + } - /** - * Pop un valor del principio de la cola. - * - * @return boolean: Verdad si fue exitoso. - */ - public boolean pop() { - if (this.cola != null) { - String cola[] = new String[this.cola.length - 1]; - // Nueva array sin el valor del primer - System.arraycopy(this.cola, 1, cola, 0, cola.length); - this.cola = cola; - size--; - return true; - } - else { - return false; - } - } + /** + * Pop un valor del principio de la cola. + * + * @return boolean: Verdad si fue exitoso. + */ + public boolean pop() { + if (this.cola != null) { + String cola[] = new String[this.cola.length - 1]; + // Nueva array sin el valor del primer + System.arraycopy(this.cola, 1, cola, 0, cola.length); + this.cola = cola; + size--; + return true; + } + else { + return false; + } + } - /** - * Peek al valor que está al principio de la cola. - * - * @return int: El valor que está al principio de la cola. - */ - public int peek() { - if (this.cola != null && size() > 0) { - return Integer.valueOf(cola[0]); - } - else { - return Integer.MIN_VALUE; - } - } + /** + * Peek al valor que está al principio de la cola. + * + * @return int: El valor que está al principio de la cola. + */ + public int peek() { + if (this.cola != null && size() > 0) { + return Integer.valueOf(cola[0]); + } + else { + return Integer.MIN_VALUE; + } + } - /** - * Devolver la cantidad de elementos que están en la cola. - * - * @return int: La cantidad de elementos. - */ - public int size() { - return size; - } + /** + * Devolver la cantidad de elementos que están en la cola. + * + * @return int: La cantidad de elementos. + */ + public int size() { + return size; + } - /** - * Devolver el valor que está en un indice de la cola. - * - * @param indice int: El indice que desea devolver. - * @return String: El valor que está guardado en el indice. - */ - public String getIndice(int indice) { - if (cola != null && indice >= 0 && indice < cola.length) { - return cola[indice]; - } - else { - return null; - } - } + /** + * Devolver el valor que está en un indice de la cola. + * + * @param indice int: El indice que desea devolver. + * + * @return String: El valor que está guardado en el indice. + */ + public String getIndice(int indice) { + if (cola != null && indice >= 0 && indice < cola.length) { + return cola[indice]; + } + else { + 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; + /** + * 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); - } - } + 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++; - } - } + /** + * 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 64e5db4..7f9c930 100644 --- a/src/cl/cromer/estructuras/ColaController.java +++ b/src/cl/cromer/estructuras/ColaController.java @@ -17,190 +17,190 @@ import java.util.logging.Level; * @author Chris Cromer */ public class ColaController implements Initializable { - /** - * La caja para ingresar textos. - */ - @FXML - private TextFieldLimited valorCola; + /** + * La caja para ingresar textos. + */ + @FXML + private TextFieldLimited valorCola; - /** - * Donde poner el contenido de array. - */ - @FXML - private VBox contenidoCola; + /** + * Donde poner el contenido de array. + */ + @FXML + private VBox contenidoCola; - /** - * Donde va el codigo a mostrar a la pantalla. - */ - @FXML - private Text codigoCola; + /** + * Donde va el codigo a mostrar a la pantalla. + */ + @FXML + private Text codigoCola; - /** - * 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 cola usado en la aplicación. - */ - private Cola cola; + /** + * La cola usado en la aplicación. + */ + private Cola cola; - /** - * 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; - cola = new Cola(); + cola = new Cola(); - scene = null; - Colores colores = new Colores(); + scene = null; + Colores colores = new Colores(); - for (int i = 9; i >= 0; i--) { - contenidoCola.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i))); - colores.siguinteColor(); - } - } + for (int i = 9; i >= 0; i--) { + contenidoCola.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i))); + colores.siguinteColor(); + } + } - /** - * Llenar la cola con numeros al azar. - */ - @FXML - protected void botonLlenar() { - if (scene == null) { - scene = contenidoCola.getScene(); - grafico = new Grafico(scene); - } + /** + * Llenar la cola con numeros al azar. + */ + @FXML + protected void botonLlenar() { + if (scene == null) { + scene = contenidoCola.getScene(); + grafico = new Grafico(scene); + } - cola.llenar(); - generarGrafico(); - } + cola.llenar(); + 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)); - } - } + /** + * 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. - */ - @FXML - protected void botonVaciar() { - if (scene == null) { - scene = contenidoCola.getScene(); - grafico = new Grafico(scene); - } + /** + * Vaciar la cola de todos los valores. + */ + @FXML + protected void botonVaciar() { + if (scene == null) { + scene = contenidoCola.getScene(); + grafico = new Grafico(scene); + } - cola = new Cola(); - generarGrafico(); - } + cola = new Cola(); + generarGrafico(); + } - /** - * Push un valor a la cola y mostrar el codigo en la pantalla. - */ - @FXML - protected void botonPush() { - if (scene == null) { - scene = contenidoCola.getScene(); - grafico = new Grafico(scene); - } + /** + * Push un valor a la cola y mostrar el codigo en la pantalla. + */ + @FXML + protected void botonPush() { + if (scene == null) { + scene = contenidoCola.getScene(); + grafico = new Grafico(scene); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/cola/push")).useDelimiter("\\Z").next(); - codigoCola.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/cola/push")).useDelimiter("\\Z").next(); + codigoCola.setText(codigoTexto); - if (valorCola.getText() != null && !valorCola.getText().trim().equals("")) { - try { - if (cola.size() < 10) { - cola.push(Integer.valueOf(valorCola.getText())); - valorCola.setText(""); - generarGrafico(); - } - else { - Main.mostrarError(resourceBundle.getString("colaLlena"), resourceBundle); - } - } - catch (NumberFormatException exception) { - // El error no es fatal, sigue - Logs.log(Level.WARNING, "No es tipo int."); - Main.mostrarError(resourceBundle.getString("colaNoValor"), resourceBundle); - } - } - else { - Main.mostrarError(resourceBundle.getString("colaNoValor"), resourceBundle); - } - } + if (valorCola.getText() != null && ! valorCola.getText().trim().equals("")) { + try { + if (cola.size() < 10) { + cola.push(Integer.valueOf(valorCola.getText())); + valorCola.setText(""); + generarGrafico(); + } + else { + Main.mostrarError(resourceBundle.getString("colaLlena"), resourceBundle); + } + } + catch (NumberFormatException exception) { + // El error no es fatal, sigue + Logs.log(Level.WARNING, "No es tipo int."); + Main.mostrarError(resourceBundle.getString("colaNoValor"), resourceBundle); + } + } + else { + Main.mostrarError(resourceBundle.getString("colaNoValor"), resourceBundle); + } + } - /** - * Pop un valor de la pila si existe y mostrar el codigo en la pantalla. - */ - @FXML - protected void botonPop() { - if (scene == null) { - scene = contenidoCola.getScene(); - grafico = new Grafico(scene); - } + /** + * Pop un valor de la pila si existe y mostrar el codigo en la pantalla. + */ + @FXML + protected void botonPop() { + if (scene == null) { + scene = contenidoCola.getScene(); + grafico = new Grafico(scene); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/cola/pop")).useDelimiter("\\Z").next(); - codigoCola.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/cola/pop")).useDelimiter("\\Z").next(); + codigoCola.setText(codigoTexto); - if (cola.size() > 0) { - if (!cola.pop()) { - Main.mostrarError(resourceBundle.getString("colaVacia"), resourceBundle); - } - else { - generarGrafico(); - } - } - else { - Main.mostrarError(resourceBundle.getString("colaVacia"), resourceBundle); - } - } + if (cola.size() > 0) { + if (! cola.pop()) { + Main.mostrarError(resourceBundle.getString("colaVacia"), resourceBundle); + } + else { + generarGrafico(); + } + } + else { + Main.mostrarError(resourceBundle.getString("colaVacia"), resourceBundle); + } + } - /** - * Peek a ver si existe un elemento en la pila y mostrar el codigo en la pantalla - * Si existe un valor destacarlo. - */ - @FXML - protected void botonPeek() { - if (scene == null) { - scene = contenidoCola.getScene(); - grafico = new Grafico(scene); - } + /** + * Peek a ver si existe un elemento en la pila y mostrar el codigo en la pantalla + * Si existe un valor destacarlo. + */ + @FXML + protected void botonPeek() { + if (scene == null) { + scene = contenidoCola.getScene(); + grafico = new Grafico(scene); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/cola/peek")).useDelimiter("\\Z").next(); - codigoCola.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/cola/peek")).useDelimiter("\\Z").next(); + codigoCola.setText(codigoTexto); - int encontrado = cola.peek(); - if (encontrado != Integer.MIN_VALUE) { - generarGrafico(); - grafico.destacar("#caja_" + 0, Grafico.RECTANGULO); - grafico.destacar("#texto_" + 0, Grafico.TEXTO); - } - else { - Main.mostrarError(resourceBundle.getString("colaVacia"), resourceBundle); - } - } + int encontrado = cola.peek(); + if (encontrado != Integer.MIN_VALUE) { + generarGrafico(); + grafico.destacar("#caja_" + 0, Grafico.RECTANGULO); + grafico.destacar("#texto_" + 0, Grafico.TEXTO); + } + else { + Main.mostrarError(resourceBundle.getString("colaVacia"), resourceBundle); + } + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/Colores.java b/src/cl/cromer/estructuras/Colores.java index 1f3dcb0..7fe4aa5 100644 --- a/src/cl/cromer/estructuras/Colores.java +++ b/src/cl/cromer/estructuras/Colores.java @@ -8,90 +8,90 @@ import javafx.scene.paint.Color; * @author Chris Cromer */ public class Colores { - /** - * Cuantos colores estan definidos en esta clase. - */ - static final public int MAX_COLORS = 7; + /** + * Cuantos colores estan definidos en esta clase. + */ + static final public int MAX_COLORS = 7; - /** - * El color actual en forma numerica. - */ - private int color; + /** + * El color actual en forma numerica. + */ + private int color; - /** - * El color de texto actual. - */ - private Color texto; + /** + * El color de texto actual. + */ + private Color texto; - /** - * El color de fondo actual. - */ - private Color fondo; + /** + * El color de fondo actual. + */ + private Color fondo; - /** - * Inicializar el primer color. - */ - public Colores() { - siguinteColor(); - } + /** + * Inicializar el primer color. + */ + public Colores() { + siguinteColor(); + } - /** - * Cambiar el color al siguinte. Si no hay, voler al primer. - */ - public void siguinteColor() { - switch (color) { - case 1: - color = 2; - texto = Color.WHITE; - fondo = Color.RED; - break; - case 2: - color = 3; - texto = Color.BLACK; - fondo = Color.WHITE; - break; - case 3: - color = 4; - texto = Color.BLACK; - fondo = Color.PINK; - break; - case 4: - color = 5; - texto = Color.BLACK; - fondo = Color.YELLOW; - break; - case 5: - color = 6; - texto = Color.BLACK; - fondo = Color.GREEN; - break; - case 6: - color = 7; - texto = Color.BLACK; - fondo = Color.ORANGE; - break; - default: - color = 1; - texto = Color.WHITE; - fondo = Color.BLUE; - } - } + /** + * Cambiar el color al siguinte. Si no hay, voler al primer. + */ + public void siguinteColor() { + switch (color) { + case 1: + color = 2; + texto = Color.WHITE; + fondo = Color.RED; + break; + case 2: + color = 3; + texto = Color.BLACK; + fondo = Color.WHITE; + break; + case 3: + color = 4; + texto = Color.BLACK; + fondo = Color.PINK; + break; + case 4: + color = 5; + texto = Color.BLACK; + fondo = Color.YELLOW; + break; + case 5: + color = 6; + texto = Color.BLACK; + fondo = Color.GREEN; + break; + case 6: + color = 7; + texto = Color.BLACK; + fondo = Color.ORANGE; + break; + default: + color = 1; + texto = Color.WHITE; + fondo = Color.BLUE; + } + } - /** - * Devolver el color del texto actual. - * - * @return Color: Color del texto. - */ - public Color getTexto() { - return texto; - } + /** + * Devolver el color del texto actual. + * + * @return Color: Color del texto. + */ + public Color getTexto() { + return texto; + } - /** - * Devolver el color del fondo actual. - * - * @return Color: Color del fondo. - */ - public Color getFondo() { - return fondo; - } + /** + * Devolver el color del fondo actual. + * + * @return Color: Color del fondo. + */ + public Color getFondo() { + return fondo; + } } diff --git a/src/cl/cromer/estructuras/Enlace.java b/src/cl/cromer/estructuras/Enlace.java index 8a78b7b..ba96b66 100644 --- a/src/cl/cromer/estructuras/Enlace.java +++ b/src/cl/cromer/estructuras/Enlace.java @@ -6,45 +6,45 @@ package cl.cromer.estructuras; * @author Chris Cromer */ interface Enlace { - /** - * Devolver la llave. - * - * @return int: La llave. - */ - int getLlave(); + /** + * Devolver la llave. + * + * @return int: La llave. + */ + int getLlave(); - /** - * Cambiar el valor de la llave. - * - * @param llave int: El valor de la llave. - */ - void setLlave(int llave); + /** + * Cambiar el valor de la llave. + * + * @param llave int: El valor de la llave. + */ + void setLlave(int llave); - /** - * Devolver el siguente enlace. - * - * @return Object: El enlace a devolver. - */ - Object getSiguiente(); + /** + * Devolver el siguente enlace. + * + * @return Object: El enlace a devolver. + */ + Object getSiguiente(); - /** - * Cambiar el siguiente enlace. - * - * @param siguiente Object: El siguiente enlace nuevo. - */ - void setSiguiente(Object siguiente); + /** + * Cambiar el siguiente enlace. + * + * @param siguiente Object: El siguiente enlace nuevo. + */ + void setSiguiente(Object siguiente); - /** - * Devolver el enlace previo. - * - * @return Object: El enlace previo. - */ - Object getPrevio(); + /** + * Devolver el enlace previo. + * + * @return Object: El enlace previo. + */ + Object getPrevio(); - /** - * Cambiar el previo enlace. - * - * @param previo Object: El enlace previo nuevo. - */ - void setPrevio(Object previo); + /** + * Cambiar el previo enlace. + * + * @param previo Object: El enlace previo nuevo. + */ + void setPrevio(Object previo); } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/EnlaceCircular.java b/src/cl/cromer/estructuras/EnlaceCircular.java index 6f6866e..2c570f7 100644 --- a/src/cl/cromer/estructuras/EnlaceCircular.java +++ b/src/cl/cromer/estructuras/EnlaceCircular.java @@ -6,73 +6,73 @@ package cl.cromer.estructuras; * @author Chris Cromer */ final public class EnlaceCircular implements Enlace { - /** - * La llave. - */ - private int llave; + /** + * La llave. + */ + private int llave; - /** - * El siguiente enlace. - */ - private EnlaceCircular siguiente; + /** + * El siguiente enlace. + */ + private EnlaceCircular siguiente; - /** - * Incializar. - */ - public EnlaceCircular() { - siguiente = null; - } + /** + * Incializar. + */ + public EnlaceCircular() { + siguiente = null; + } - /** - * Devolver la llave. - * - * @return int: La llave. - */ - public int getLlave() { - return llave; - } + /** + * Devolver la llave. + * + * @return int: La llave. + */ + public int getLlave() { + return llave; + } - /** - * Cambiar el valor de la llave. - * - * @param llave int: El valor de la llave. - */ - public void setLlave(int llave) { - this.llave = llave; - } + /** + * Cambiar el valor de la llave. + * + * @param llave int: El valor de la llave. + */ + public void setLlave(int llave) { + this.llave = llave; + } - /** - * Devolver el siguiente enlace. - * - * @return EnlaceCircular: El enlace a devolver. - */ - public EnlaceCircular getSiguiente() { - return siguiente; - } + /** + * Devolver el siguiente enlace. + * + * @return EnlaceCircular: El enlace a devolver. + */ + public EnlaceCircular getSiguiente() { + return siguiente; + } - /** - * Cambiar el siguiente enlace. - * - * @param siguiente Object: El siguiente enlace nuevo de tipo {@link EnlaceCircular}. - */ - public void setSiguiente(Object siguiente) { - this.siguiente = (EnlaceCircular) siguiente; - } + /** + * Cambiar el siguiente enlace. + * + * @param siguiente Object: El siguiente enlace nuevo de tipo {@link EnlaceCircular}. + */ + public void setSiguiente(Object siguiente) { + this.siguiente = (EnlaceCircular) siguiente; + } - /** - * Devolver el enlace previo. - * - * @return EnlaceCircular: El enlace previo. - */ - public EnlaceCircular getPrevio() { - return null; - } + /** + * Devolver el enlace previo. + * + * @return EnlaceCircular: El enlace previo. + */ + public EnlaceCircular getPrevio() { + return null; + } - /** - * Dummy metodo para usar interface {@link Enlace} - * - * @param previo Object: El enlace previo nuevo de tipo {@link EnlaceCircular}. - */ - public void setPrevio(Object previo) { - } + /** + * Dummy metodo para usar interface {@link Enlace} + * + * @param previo Object: El enlace previo nuevo de tipo {@link EnlaceCircular}. + */ + public void setPrevio(Object previo) { + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/EnlaceNormal.java b/src/cl/cromer/estructuras/EnlaceNormal.java index adefe20..e0702e3 100644 --- a/src/cl/cromer/estructuras/EnlaceNormal.java +++ b/src/cl/cromer/estructuras/EnlaceNormal.java @@ -6,80 +6,80 @@ package cl.cromer.estructuras; * @author Chris Cromer */ final public class EnlaceNormal implements Enlace { - /** - * La llave. - */ - private int llave; + /** + * La llave. + */ + private int llave; - /** - * El siguiente enlace. - */ - private EnlaceNormal siguiente; + /** + * El siguiente enlace. + */ + private EnlaceNormal siguiente; - /** - * El enlace previo por doble enlazada. - */ - private EnlaceNormal previo; + /** + * El enlace previo por doble enlazada. + */ + private EnlaceNormal previo; - /** - * Incializar. - */ - public EnlaceNormal() { - siguiente = null; - previo = null; - } + /** + * Incializar. + */ + public EnlaceNormal() { + siguiente = null; + previo = null; + } - /** - * Devolver la llave. - * - * @return int: La llave. - */ - public int getLlave() { - return llave; - } + /** + * Devolver la llave. + * + * @return int: La llave. + */ + public int getLlave() { + return llave; + } - /** - * Cambiar el valor de la llave. - * - * @param llave int: El valor de la llave. - */ - public void setLlave(int llave) { - this.llave = llave; - } + /** + * Cambiar el valor de la llave. + * + * @param llave int: El valor de la llave. + */ + public void setLlave(int llave) { + this.llave = llave; + } - /** - * Devolver el siguiente enlace. - * - * @return EnlaceNormal: El enlace a devolver. - */ - public EnlaceNormal getSiguiente() { - return siguiente; - } + /** + * Devolver el siguiente enlace. + * + * @return EnlaceNormal: El enlace a devolver. + */ + public EnlaceNormal getSiguiente() { + return siguiente; + } - /** - * Cambiar el siguiente enlace. - * - * @param siguiente Object: El siguiente enlace nuevo de tipo {@link EnlaceNormal}. - */ - public void setSiguiente(Object siguiente) { - this.siguiente = (EnlaceNormal) siguiente; - } + /** + * Cambiar el siguiente enlace. + * + * @param siguiente Object: El siguiente enlace nuevo de tipo {@link EnlaceNormal}. + */ + public void setSiguiente(Object siguiente) { + this.siguiente = (EnlaceNormal) siguiente; + } - /** - * Devolver el enlace previo. - * - * @return EnlaceNormal: El enlace previo. - */ - public EnlaceNormal getPrevio() { - return previo; - } + /** + * Devolver el enlace previo. + * + * @return EnlaceNormal: El enlace previo. + */ + public EnlaceNormal getPrevio() { + return previo; + } - /** - * Cambiar el previo enlace. - * - * @param previo Object: El enlace previo nuevo de tipo {@link EnlaceNormal}. - */ - public void setPrevio(Object previo) { - this.previo = (EnlaceNormal) previo; - } + /** + * Cambiar el previo enlace. + * + * @param previo Object: El enlace previo nuevo de tipo {@link EnlaceNormal}. + */ + public void setPrevio(Object previo) { + this.previo = (EnlaceNormal) previo; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/HashTable.java b/src/cl/cromer/estructuras/HashTable.java index 23a6362..5b7af51 100644 --- a/src/cl/cromer/estructuras/HashTable.java +++ b/src/cl/cromer/estructuras/HashTable.java @@ -27,9 +27,9 @@ public class HashTable { * @param tamano int: El tamaño maximo de la tabla hash. */ public HashTable(int tamano) { - this.tamano = tamano; - hashArray = new HashItem[tamano]; - } + this.tamano = tamano; + hashArray = new HashItem[tamano]; + } /** * Devolver la cantidad de elementos que están en la tabla. @@ -37,38 +37,38 @@ public class HashTable { * @return int: La cantidad. */ public int size() { - return size; - } + return size; + } - /** - * Este metodo crea un hash muy único. - * - * @param string String: El string a hashear. - * - * @return int: El hash a devolver. - */ - @SuppressWarnings("unused") - public int hashMejor(String string) { - int intLength = string.length() / 4; - int sum = 0; - for (int j = 0; j < intLength; j++) { - char c[] = string.substring(j * 4, (j * 4) + 4).toCharArray(); - int mult = 1; - for (char aC : c) { - sum = sum + aC * mult; - mult = mult * 256; - } - } + /** + * Este metodo crea un hash muy único. + * + * @param string String: El string a hashear. + * + * @return int: El hash a devolver. + */ + @SuppressWarnings("unused") + public int hashMejor(String string) { + int intLength = string.length() / 4; + int sum = 0; + for (int j = 0; j < intLength; j++) { + char c[] = string.substring(j * 4, (j * 4) + 4).toCharArray(); + int mult = 1; + for (char aC : c) { + sum = sum + aC * mult; + mult = mult * 256; + } + } - char c[] = string.substring(intLength * 4).toCharArray(); - int mult = 1; - for (char aC : c) { - sum = sum + aC * mult; - mult = mult * 256; - } + char c[] = string.substring(intLength * 4).toCharArray(); + int mult = 1; + for (char aC : c) { + sum = sum + aC * mult; + mult = mult * 256; + } - return (Math.abs(sum) % tamano); - } + return (Math.abs(sum) % tamano); + } /** * Insertar una llave y valor en la tabla hash. @@ -79,45 +79,45 @@ public class HashTable { * @return boolean: Verdad si fue insertado, sino está llena la tabla hash. */ public boolean insertar(String llave, int valor) { - HashItem hashItem = new HashItem(llave, valor); - int hashIndice = hash(hashItem.getLlave()); - int i = 0; - while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) { - if (hashArray[hashIndice].getLlave().equals(llave)) { - return false; - } - hashIndice++; - hashIndice = hashIndice % tamano; - i++; - } - if (i == 10) { - return false; - } - else { - hashItem.setIndice(hashIndice); - hashArray[hashIndice] = hashItem; - size++; - return true; - } - } + HashItem hashItem = new HashItem(llave, valor); + int hashIndice = hash(hashItem.getLlave()); + int i = 0; + while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) { + if (hashArray[hashIndice].getLlave().equals(llave)) { + return false; + } + hashIndice++; + hashIndice = hashIndice % tamano; + i++; + } + if (i == 10) { + return false; + } + else { + hashItem.setIndice(hashIndice); + hashArray[hashIndice] = hashItem; + size++; + return true; + } + } - /** - * 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; - } + /** + * 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. @@ -127,21 +127,21 @@ public class HashTable { * @return boolean: Verdad si fue borrado, sino no existiá. */ public boolean eliminar(String llave) { - HashItem hashItem = new HashItem(llave, 0); - int hashIndice = hash(hashItem.getLlave()); - int i = 0; - while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) { - if (hashArray[hashIndice].getLlave().equals(llave)) { - hashArray[hashIndice] = null; - size--; - return true; - } - hashIndice++; - hashIndice = hashIndice % tamano; - i++; - } - return false; - } + HashItem hashItem = new HashItem(llave, 0); + int hashIndice = hash(hashItem.getLlave()); + int i = 0; + while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) { + if (hashArray[hashIndice].getLlave().equals(llave)) { + hashArray[hashIndice] = null; + size--; + return true; + } + hashIndice++; + hashIndice = hashIndice % tamano; + i++; + } + return false; + } /** * Buscar una llave en la tabla hash. @@ -151,27 +151,27 @@ public class HashTable { * @return HashItem: Devolver el elemento que contine la llave. */ public HashItem buscar(String llave) { - for (int i = 0; i < tamano; i++) { - if (hashArray[i] != null && hashArray[i].getLlave().equals(llave)) { - return hashArray[i]; - } - } - return null; - } + for (int i = 0; i < tamano; i++) { + if (hashArray[i] != null && hashArray[i].getLlave().equals(llave)) { + return hashArray[i]; + } + } + return null; + } - /** - * Devolver el valor que está guardado en cada indice. Se usa para construir la grafica. - * - * @param indice int: El indice que desea ver. - * - * @return String: El valor que está en dicho indice. - */ - public HashItem getIndice(int indice) { - if (indice >= 0 && indice < hashArray.length) { - return hashArray[indice]; - } - else { - return null; - } - } + /** + * Devolver el valor que está guardado en cada indice. Se usa para construir la grafica. + * + * @param indice int: El indice que desea ver. + * + * @return String: El valor que está en dicho indice. + */ + public HashItem getIndice(int indice) { + if (indice >= 0 && indice < hashArray.length) { + return hashArray[indice]; + } + else { + return null; + } + } } diff --git a/src/cl/cromer/estructuras/HashTableController.java b/src/cl/cromer/estructuras/HashTableController.java index bd4c795..439c268 100644 --- a/src/cl/cromer/estructuras/HashTableController.java +++ b/src/cl/cromer/estructuras/HashTableController.java @@ -64,7 +64,7 @@ public class HashTableController implements Initializable { /** * Inicializar todos los datos y dibujar las graficas. * - * @param location URL: El URL de fxml en uso. + * @param location URL: El URL de fxml en uso. * @param resourceBundle ResourceBundle: Tiene datos de idioma. */ @Override @@ -98,7 +98,7 @@ public class HashTableController implements Initializable { for (int i = 0; i < 10; i++) { int numero = random.nextInt(rango) + minimo; - while (!hashTable.insertar(palabras.getPalabra(), numero)) { + while (! hashTable.insertar(palabras.getPalabra(), numero)) { if (hashTable.size() == 10) { break; } @@ -107,6 +107,40 @@ public class HashTableController implements Initializable { generarGrafico(); } + /** + * Crear el hashTable de tamaño 10. + */ + private void initializeHashTable() { + scene = contenidoHashTable.getScene(); + grafico = new Grafico(scene); + this.hashTable = new HashTable(10); + } + + /** + * Poner los valores en el grafico. + */ + private void generarGrafico() { + grafico.removerDestacar(); + for (int i = 0; i < 10; i++) { + if (hashTable.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(hashTable.getIndice(i).getLlave()); + text = (Text) scene.lookup("#valor_texto_" + String.valueOf(i)); + text.setText(String.valueOf(hashTable.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(""); + } + } + } + /** * Vaciar el hashTable de todos los valores. */ @@ -131,10 +165,10 @@ public class HashTableController implements Initializable { // Mostrar el codigo /*String tipo = (hashTable.isOrdered()) ? "Ordenado" : "Simple"; - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/insertar")).useDelimiter("\\Z").next(); - codigoHashTable.setText(codigoTexto);*/ + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/insertar")).useDelimiter("\\Z").next(); + codigoHashTable.setText(codigoTexto);*/ - if (llaveHashTable.getText() != null && !llaveHashTable.getText().trim().equals("") && valorHashTable.getText() != null && !valorHashTable.getText().trim().equals("")) { + if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("") && valorHashTable.getText() != null && ! valorHashTable.getText().trim().equals("")) { try { boolean exito = hashTable.insertar(llaveHashTable.getText().trim(), Integer.valueOf(valorHashTable.getText())); if (exito) { @@ -173,11 +207,11 @@ public class HashTableController implements Initializable { // Mostrar el codigo /*String tipo = (hashTable.isOrdered()) ? "Ordenado" : "Simple"; - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/eliminar")).useDelimiter("\\Z").next(); - codigoHashTable.setText(codigoTexto);*/ + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/eliminar")).useDelimiter("\\Z").next(); + codigoHashTable.setText(codigoTexto);*/ try { - if (llaveHashTable.getText() != null && !llaveHashTable.getText().trim().equals("")) { + if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) { boolean exito = hashTable.eliminar(llaveHashTable.getText()); if (exito) { llaveHashTable.setText(""); @@ -211,11 +245,11 @@ public class HashTableController implements Initializable { // Mostrar el codigo /*String tipo = (hashTable.isOrdered()) ? "Ordenado" : "Simple"; - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/buscar")).useDelimiter("\\Z").next(); - codigoHashTable.setText(codigoTexto);*/ + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/buscar")).useDelimiter("\\Z").next(); + codigoHashTable.setText(codigoTexto);*/ try { - if (llaveHashTable.getText() != null && !llaveHashTable.getText().trim().equals("")) { + if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) { HashItem hashItem = hashTable.buscar(llaveHashTable.getText()); if (hashItem != null) { generarGrafico(); @@ -240,39 +274,5 @@ public class HashTableController implements Initializable { Logs.log(Level.WARNING, "No es tipo int."); Main.mostrarError(resourceBundle.getString("tablaHashNoLlave"), resourceBundle); } - } - - /** - * Crear el hashTable de tamaño 10. - */ - private void initializeHashTable() { - scene = contenidoHashTable.getScene(); - grafico = new Grafico(scene); - this.hashTable = new HashTable(10); - } - - /** - * Poner los valores en el grafico. - */ - private void generarGrafico() { - grafico.removerDestacar(); - for (int i = 0; i < 10; i++) { - if (hashTable.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(hashTable.getIndice(i).getLlave()); - text = (Text) scene.lookup("#valor_texto_" + String.valueOf(i)); - text.setText(String.valueOf(hashTable.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/InsercionController.java b/src/cl/cromer/estructuras/InsercionController.java index d7225b2..e72a0ef 100644 --- a/src/cl/cromer/estructuras/InsercionController.java +++ b/src/cl/cromer/estructuras/InsercionController.java @@ -46,7 +46,7 @@ public class InsercionController implements Initializable { /** * Inicializar todos los datos y dibujar las graficas. * - * @param location URL: El URL de fxml en uso. + * @param location URL: El URL de fxml en uso. * @param resourceBundle ResourceBundle: Tiene datos de idioma. */ @Override @@ -112,7 +112,7 @@ public class InsercionController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/insercion/ordenar")).useDelimiter("\\Z").next(); codigoInsercion.setText(codigoTexto); - if (!array.insercion(true)) { + if (! array.insercion(true)) { Main.mostrarError(resourceBundle.getString("insercionYaOrdenado"), resourceBundle); } @@ -132,10 +132,10 @@ public class InsercionController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/insercion/ordenar")).useDelimiter("\\Z").next(); codigoInsercion.setText(codigoTexto); - if (!array.insercion(false)) { + if (! array.insercion(false)) { Main.mostrarError(resourceBundle.getString("insercionYaOrdenado"), resourceBundle); } - generarGrafico(); + generarGrafico(); } } diff --git a/src/cl/cromer/estructuras/ListaEnlazada.java b/src/cl/cromer/estructuras/ListaEnlazada.java index f36023a..abde781 100644 --- a/src/cl/cromer/estructuras/ListaEnlazada.java +++ b/src/cl/cromer/estructuras/ListaEnlazada.java @@ -6,172 +6,176 @@ package cl.cromer.estructuras; * @author Chris Cromer */ final public class ListaEnlazada { - /** - * El enlace principal de la lista. - */ - private Enlace lista; + /** + * El enlace principal de la lista. + */ + private Enlace lista; - /** - * La cantidad de enlaces que están en la lista. - */ - private int size; + /** + * La cantidad de enlaces que están en la lista. + */ + private int size; - /** - * El tipo de lista enlazada. - */ - private int tipo; + /** + * El tipo de lista enlazada. + */ + private int tipo; - /** - * Inicilizar. - */ - public ListaEnlazada() { - lista = null; - } + /** + * Inicilizar. + */ + public ListaEnlazada() { + lista = null; + } - /** - * Devolver la cantidad de enlaces que están en la lista. - * - * @return int: La cantidad. - */ - public int size() { - return size; - } + /** + * Devolver el tipo de lista. + * + * @return int: El tipo. + */ + public int getTipo() { + return tipo; + } - /** - * Devolver el tipo de lista. - * - * @return int: El tipo. - */ - public int getTipo() { - return tipo; - } + /** + * Cambiar el tipo de lista. + * + * @param tipo int: El tipo a cambiar. + */ + public void setTipo(int tipo) { + this.tipo = tipo; + } - /** - * Cambiar el tipo de lista. - * - * @param tipo int: El tipo a cambiar. - */ - public void setTipo(int tipo) { - this.tipo = tipo; - } + /** + * Insertar una llave en la lista. + * + * @param llave int: La llave a insertar. + * + * @return boolean: Verdad si fue insertado, sino falso. + */ + public boolean insertar(int llave) { + if (buscar(llave) == null) { + // Crear una enlace y agregarla a la lista + Enlace nuevo = new EnlaceNormal(); + nuevo.setLlave(llave); + nuevo.setSiguiente(lista); + if (lista != null) { + lista.setPrevio(nuevo); + } + lista = nuevo; + size++; + return true; + } + else { + // Se falló porque la llave ya existe + return false; + } + } - /** - * 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; - } - } + /** + * 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; + } + } - /** - * Insertar una llave en la lista. - * - * @param llave int: La llave a insertar. - * @return boolean: Verdad si fue insertado, sino falso. - */ - public boolean insertar(int llave) { - if (buscar(llave) == null) { - // Crear una enlace y agregarla a la lista - Enlace nuevo = new EnlaceNormal(); - nuevo.setLlave(llave); - nuevo.setSiguiente(lista); - if (lista != null) { - lista.setPrevio(nuevo); - } - lista = nuevo; - size++; - return true; - } - else { - // Se falló porque la llave ya existe - return false; - } - } + /** + * Eliminar un enlace de la lista. + * + * @param llave int: La llave a eliminar. + * + * @return boolean: Verdad si fue borrado, sino falso. + */ + public boolean eliminar(int llave) { + if (lista != null) { + // La lista no es vacia + Enlace lista = this.lista; + Enlace previo = lista; + while (lista.getLlave() != llave) { + // Buscar hasta la llave es encontraddo + if (lista.getSiguiente() != null) { + // Buscar en la siguiente enlace + previo = lista; + lista = (Enlace) lista.getSiguiente(); + } + else { + // No se encuentra + return false; + } + } + // Se encontró + if (lista == this.lista) { + // Si es la primera enlace, cambiarla al siguiente enlace + this.lista = (Enlace) this.lista.getSiguiente(); + if (this.lista.getPrevio() != null) { + this.lista.setPrevio(null); + } + } + else { + // Sino cortar esta enlace de la lista + previo.setSiguiente(lista.getSiguiente()); + } + size--; + return true; + } + else { + // La lista es vacia, no hay nada para eliminar + return false; + } + } - /** - * Eliminar un enlace de la lista. - * - * @param llave int: La llave a eliminar. - * @return boolean: Verdad si fue borrado, sino falso. - */ - public boolean eliminar(int llave) { - if (lista != null) { - // La lista no es vacia - Enlace lista = this.lista; - Enlace previo = lista; - while (lista.getLlave() != llave) { - // Buscar hasta la llave es encontraddo - if (lista.getSiguiente() != null) { - // Buscar en la siguiente enlace - previo = lista; - lista = (Enlace) lista.getSiguiente(); - } - else { - // No se encuentra - return false; - } - } - // Se encontró - if (lista == this.lista) { - // Si es la primera enlace, cambiarla al siguiente enlace - this.lista = (Enlace) this.lista.getSiguiente(); - if (this.lista.getPrevio() != null) { - this.lista.setPrevio(null); - } - } - else { - // Sino cortar esta enlace de la lista - previo.setSiguiente(lista.getSiguiente()); - } - size--; - return true; - } - else { - // La lista es vacia, no hay nada para eliminar - return false; - } - } + /** + * Devolver un enlace con su llave y valor. + * + * @param indice int: El indice que desea ver. + * + * @return Enlace: El enlace a devolver. + */ + public Enlace getIndice(int indice) { + if (lista != null && indice >= 0 && indice < size()) { + int i = size(); + Enlace lista = this.lista; + while (i > indice + 1) { + lista = (Enlace) lista.getSiguiente(); + i--; + } + return lista; + } + else { + return null; + } + } - /** - * Devolver un enlace con su llave y valor. - * - * @param indice int: El indice que desea ver. - * @return Enlace: El enlace a devolver. - */ - public Enlace getIndice(int indice) { - if (lista != null && indice >= 0 && indice < size()) { - int i = size(); - Enlace lista = this.lista; - while (i > indice + 1) { - lista = (Enlace) lista.getSiguiente(); - i--; - } - return lista; - } - else { - return null; - } - } + /** + * Devolver la cantidad de enlaces que están en la lista. + * + * @return int: La cantidad. + */ + public int size() { + return size; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/ListaEnlazadaCircular.java b/src/cl/cromer/estructuras/ListaEnlazadaCircular.java index d951818..1acf707 100644 --- a/src/cl/cromer/estructuras/ListaEnlazadaCircular.java +++ b/src/cl/cromer/estructuras/ListaEnlazadaCircular.java @@ -6,183 +6,188 @@ package cl.cromer.estructuras; * @author Chris Cromer */ final public class ListaEnlazadaCircular { - /** - * El primer enlace. - */ - private Enlace primer; - /** - * El ultimo enlace. - */ - private Enlace ultimo; + /** + * El primer enlace. + */ + private Enlace primer; - /** - * La cantidad de enlaces que hay. - */ - private int size; + /** + * El ultimo enlace. + */ + private Enlace ultimo; - /** - * El tipo de lista enlazada. - */ - private int tipo; + /** + * La cantidad de enlaces que hay. + */ + private int size; - /** - * Inicilizar. - */ - public ListaEnlazadaCircular() { - primer = null; - ultimo = null; - } + /** + * El tipo de lista enlazada. + */ + private int tipo; - /** - * Devolver la cantidad de enlaces que están en la lista. - * - * @return int: La cantidad. - */ - public int size() { - return size; - } + /** + * Inicilizar. + */ + public ListaEnlazadaCircular() { + primer = null; + ultimo = null; + } - /** - * Devolver el tipo de lista. - * - * @return int: El tipo de lista. - */ - public int getTipo() { - return tipo; - } + /** + * Devolver el tipo de lista. + * + * @return int: El tipo de lista. + */ + public int getTipo() { + return tipo; + } - /** - * Cambiar el tipo de lista. - * - * @param tipo int: El tipo a cambiar. - */ - public void setTipo(int tipo) { - this.tipo = tipo; - } + /** + * Cambiar el tipo de lista. + * + * @param tipo int: El tipo a cambiar. + */ + public void setTipo(int tipo) { + this.tipo = tipo; + } - /** - * 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; - } - } + /** + * Insertar una llave en la lista. + * + * @param llave int: La llave a insertar. + * + * @return boolean: Verdad si fue insertado, falso si ya existe la llave. + */ + public boolean insertar(int llave) { + if (buscar(llave) == null) { + // Crear una enlace y agregarla a la lista + Enlace enlace = new EnlaceCircular(); - /** - * Insertar una llave en la lista. - * - * @param llave int: La llave a insertar. - * @return boolean: Verdad si fue insertado, falso si ya existe la llave. - */ - public boolean insertar(int llave) { - if (buscar(llave) == null) { - // Crear una enlace y agregarla a la lista - Enlace enlace = new EnlaceCircular(); + if (primer == null) { + ultimo = enlace; + } - if (primer == null) { - ultimo = enlace; - } + enlace.setLlave(llave); + enlace.setSiguiente(primer); + primer = enlace; + ultimo.setSiguiente(primer); - enlace.setLlave(llave); - enlace.setSiguiente(primer); - primer = enlace; - ultimo.setSiguiente(primer); + size++; + return true; + } + else { + // Se falló porque la llave ya existe + return false; + } + } - size++; - return true; - } - else { - // Se falló porque la llave ya existe - return false; - } - } + /** + * 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; + } + } - /** - * Eliminar un enlace de la lista. - * - * @param llave int: La llave a elminiar. - * @return boolean: Verdad se fue eliminado, falso si no estaba en la lista. - */ - public boolean eliminar(int llave) { - if (primer != null) { - // La lista no es vacia - Enlace lista = this.primer; - Enlace previo = lista; - int i = 0; - while (lista.getLlave() != llave && i < size()) { - // Buscar hasta la llave es encontraddo - if (lista.getSiguiente() != null) { - // Buscar en la siguiente enlace - previo = lista; - lista = (Enlace) lista.getSiguiente(); - } - i++; - } + /** + * Devolver la cantidad de enlaces que están en la lista. + * + * @return int: La cantidad. + */ + public int size() { + return size; + } - if (lista.getLlave() != llave) { - // No se encontró - return false; - } + /** + * Eliminar un enlace de la lista. + * + * @param llave int: La llave a elminiar. + * + * @return boolean: Verdad se fue eliminado, falso si no estaba en la lista. + */ + public boolean eliminar(int llave) { + if (primer != null) { + // La lista no es vacia + Enlace lista = this.primer; + Enlace previo = lista; + int i = 0; + while (lista.getLlave() != llave && i < size()) { + // Buscar hasta la llave es encontraddo + if (lista.getSiguiente() != null) { + // Buscar en la siguiente enlace + previo = lista; + lista = (Enlace) lista.getSiguiente(); + } + i++; + } - // Se encontró - if (lista == this.primer) { - // Si es la primera enlace, cambiarla al sigueinte enlace - this.primer = (Enlace) this.primer.getSiguiente(); - } - else { - // Sino cortar esta enlace de la lista - previo.setSiguiente(lista.getSiguiente()); - } - size--; - return true; - } - else { - // La lista es vacia, no hay nada para eliminar - return false; - } - } + if (lista.getLlave() != llave) { + // No se encontró + return false; + } - /** - * Devolver un enlace con su llave y valor. - * - * @param indice int: El indice que desea ver. - * @return Enlace: El enlace a devolver. - */ - public Enlace getIndice(int indice) { - if (primer != null && indice >= 0 && indice < size()) { - int i = size(); - Enlace lista = this.primer; - while (i > indice + 1) { - lista = (Enlace) lista.getSiguiente(); - i--; - } - return lista; - } - else { - return null; - } - } + // Se encontró + if (lista == this.primer) { + // Si es la primera enlace, cambiarla al sigueinte enlace + this.primer = (Enlace) this.primer.getSiguiente(); + } + else { + // Sino cortar esta enlace de la lista + previo.setSiguiente(lista.getSiguiente()); + } + size--; + return true; + } + else { + // La lista es vacia, no hay nada para eliminar + return false; + } + } + + /** + * Devolver un enlace con su llave y valor. + * + * @param indice int: El indice que desea ver. + * + * @return Enlace: El enlace a devolver. + */ + public Enlace getIndice(int indice) { + if (primer != null && indice >= 0 && indice < size()) { + int i = size(); + Enlace lista = this.primer; + while (i > indice + 1) { + lista = (Enlace) lista.getSiguiente(); + i--; + } + return lista; + } + else { + return null; + } + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/ListaEnlazadaTipos.java b/src/cl/cromer/estructuras/ListaEnlazadaTipos.java index 7bca1f3..098f8de 100644 --- a/src/cl/cromer/estructuras/ListaEnlazadaTipos.java +++ b/src/cl/cromer/estructuras/ListaEnlazadaTipos.java @@ -6,51 +6,53 @@ package cl.cromer.estructuras; * @author Chris Cromer */ final public class ListaEnlazadaTipos { - /** - * Tipo simple. - */ - static final public int SIMPLE = 0; - /** - * Tipo circular. - */ - static final public int CIRCULAR = 1; - /** - * Tipo doblemente enlazada. - */ - static final public int DOBLEMENTE_ENLAZADA = 2; + /** + * Tipo simple. + */ + static final public int SIMPLE = 0; - /** - * El tipo elegido. - */ - final private int tipo; + /** + * Tipo circular. + */ + static final public int CIRCULAR = 1; - /** - * Inicilizar el tipo de lista enlazada. - * - * @param tipo int: El tipo de lista enlazada, {@value #SIMPLE}, {@value #CIRCULAR} o {@value #DOBLEMENTE_ENLAZADA} - */ - public ListaEnlazadaTipos(int tipo) { - switch (tipo) { - case SIMPLE: - this.tipo = SIMPLE; - break; - case CIRCULAR: - this.tipo = CIRCULAR; - break; - case DOBLEMENTE_ENLAZADA: - this.tipo = DOBLEMENTE_ENLAZADA; - break; - default: - this.tipo = SIMPLE; - } - } + /** + * Tipo doblemente enlazada. + */ + static final public int DOBLEMENTE_ENLAZADA = 2; - /** - * Devolver el tipo de lista enlazada. - * - * @return int: El tipo. - */ - public int getTipo() { - return tipo; - } + /** + * El tipo elegido. + */ + final private int tipo; + + /** + * Inicilizar el tipo de lista enlazada. + * + * @param tipo int: El tipo de lista enlazada, {@value #SIMPLE}, {@value #CIRCULAR} o {@value #DOBLEMENTE_ENLAZADA} + */ + public ListaEnlazadaTipos(int tipo) { + switch (tipo) { + case SIMPLE: + this.tipo = SIMPLE; + break; + case CIRCULAR: + this.tipo = CIRCULAR; + break; + case DOBLEMENTE_ENLAZADA: + this.tipo = DOBLEMENTE_ENLAZADA; + break; + default: + this.tipo = SIMPLE; + } + } + + /** + * Devolver el tipo de lista enlazada. + * + * @return int: El tipo. + */ + public int getTipo() { + return tipo; + } } diff --git a/src/cl/cromer/estructuras/ListaEnlazdaController.java b/src/cl/cromer/estructuras/ListaEnlazdaController.java index 1042cc7..e599898 100644 --- a/src/cl/cromer/estructuras/ListaEnlazdaController.java +++ b/src/cl/cromer/estructuras/ListaEnlazdaController.java @@ -80,7 +80,7 @@ public class ListaEnlazdaController implements Initializable { /** * Inicializar todos los datos y dibujar las graficas. * - * @param location URL: El URL de fxml en uso. + * @param location URL: El URL de fxml en uso. * @param resourceBundle ResourceBundle: Tiene datos de idioma. */ @Override @@ -254,7 +254,7 @@ public class ListaEnlazdaController implements Initializable { 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("")) { + if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) { try { boolean exito; if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) { @@ -316,7 +316,7 @@ public class ListaEnlazdaController implements Initializable { codigoLista.setText(codigoTexto); try { - if (valorLista.getText() != null && !valorLista.getText().trim().equals("")) { + if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) { boolean exito; if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) { exito = listaEnlazada.eliminar(Integer.valueOf(valorLista.getText())); @@ -360,7 +360,7 @@ public class ListaEnlazdaController implements Initializable { codigoLista.setText(codigoTexto); try { - if (valorLista.getText() != null && !valorLista.getText().trim().equals("")) { + if (valorLista.getText() != null && ! valorLista.getText().trim().equals("")) { Enlace enlace; if (listaEnlazadaTipos.getTipo() != ListaEnlazadaTipos.CIRCULAR) { enlace = listaEnlazada.buscar(Integer.valueOf(valorLista.getText())); @@ -386,6 +386,6 @@ public class ListaEnlazdaController implements Initializable { // El error no es fatal, sigue Logs.log(Level.WARNING, "No es tipo int."); Main.mostrarError(resourceBundle.getString("listaNoValor"), resourceBundle); - } - } + } + } } diff --git a/src/cl/cromer/estructuras/Logs.java b/src/cl/cromer/estructuras/Logs.java index 7dae343..3cf67ca 100644 --- a/src/cl/cromer/estructuras/Logs.java +++ b/src/cl/cromer/estructuras/Logs.java @@ -12,43 +12,43 @@ import java.util.logging.SimpleFormatter; * @author Chris Cromer */ public class Logs { - /** - * Nombre de archivo para guardar los logs. - */ - static final public String LOGFILE = "./EDD.log"; + /** + * Nombre de archivo para guardar los logs. + */ + static final public String LOGFILE = "./EDD.log"; - /** - * Nombre del log. - */ - static final public String LOGNAME = "EDD"; + /** + * Nombre del log. + */ + static final public String LOGNAME = "EDD"; - /** - * Crear un logger usando {@value #LOGNAME}. Guardar los logs en el archivo de {@value #LOGFILE}. Pero solo logear si Main.DEBUG es vardad. - */ - public Logs() { - if (Main.DEBUG) { - Logger logger = Logger.getLogger(LOGNAME); - try { - FileHandler fileHandler = new FileHandler(LOGFILE, true); - logger.addHandler(fileHandler); - SimpleFormatter formatter = new SimpleFormatter(); - fileHandler.setFormatter(formatter); - } - catch (SecurityException | IOException e) { - e.printStackTrace(); - } - } - } + /** + * Crear un logger usando {@value #LOGNAME}. Guardar los logs en el archivo de {@value #LOGFILE}. Pero solo logear si Main.DEBUG es vardad. + */ + public Logs() { + if (Main.DEBUG) { + Logger logger = Logger.getLogger(LOGNAME); + try { + FileHandler fileHandler = new FileHandler(LOGFILE, true); + logger.addHandler(fileHandler); + SimpleFormatter formatter = new SimpleFormatter(); + fileHandler.setFormatter(formatter); + } + catch (SecurityException | IOException e) { + e.printStackTrace(); + } + } + } - /** - * Agregar un log al logger. - * - * @param level Level: El tipo de error o mensaje que ha sido generado. - * @param mensaje String: El mensaje de lo que pasó. - */ - static public void log(Level level, String mensaje) { - if (Main.DEBUG) { - Logger.getLogger(LOGNAME).log(level, mensaje); - } - } + /** + * Agregar un log al logger. + * + * @param level Level: El tipo de error o mensaje que ha sido generado. + * @param mensaje String: El mensaje de lo que pasó. + */ + static public void log(Level level, String mensaje) { + if (Main.DEBUG) { + Logger.getLogger(LOGNAME).log(level, mensaje); + } + } } diff --git a/src/cl/cromer/estructuras/Main.java b/src/cl/cromer/estructuras/Main.java index 1912c3c..0ac3ef8 100644 --- a/src/cl/cromer/estructuras/Main.java +++ b/src/cl/cromer/estructuras/Main.java @@ -25,79 +25,79 @@ import java.util.logging.Level; * @version 1.0.0 */ public class Main extends Application { - /** - * Estado de depuración. - */ - static final public boolean DEBUG = false; + /** + * Estado de depuración. + */ + static final public boolean DEBUG = false; - /** - * Inicilizar el logeo y lanzar la interfaz grafica. - * - * @param args String[]: Argumentos desde la consola. - */ - public static void main(String args[]) { - if (DEBUG) { - new Logs(); - } + /** + * Inicilizar el logeo y lanzar la interfaz grafica. + * + * @param args String[]: Argumentos desde la consola. + */ + public static void main(String args[]) { + if (DEBUG) { + new Logs(); + } - launch(args); - } + 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. + * + * @param mensaje String: El mensaje a mostrar. + * @param resourceBundle ResourceBundle: Contiene el idioma actual. + */ + static public void mostrarError(String mensaje, ResourceBundle resourceBundle) { + ButtonType botonCerrar = new ButtonType(resourceBundle.getString("cerrar"), ButtonBar.ButtonData.OK_DONE); + Dialog dialog = new Dialog<>(); + dialog.setTitle(resourceBundle.getString("error")); + dialog.setContentText(mensaje); + dialog.getDialogPane().getButtonTypes().add(botonCerrar); + dialog.getDialogPane().getScene().getWindow().sizeToScene(); + Main.setIcon(dialog, Main.class); + dialog.show(); + } - /** - * Mostrar una ventana con mensaje en la pantalla. - * - * @param mensaje String: El mensaje a mostrar. - * @param resourceBundle ResourceBundle: Contiene el idioma actual. - */ - static public void mostrarError(String mensaje, ResourceBundle resourceBundle) { - ButtonType botonCerrar = new ButtonType(resourceBundle.getString("cerrar"), ButtonBar.ButtonData.OK_DONE); - Dialog dialog = new Dialog<>(); - dialog.setTitle(resourceBundle.getString("error")); - dialog.setContentText(mensaje); - dialog.getDialogPane().getButtonTypes().add(botonCerrar); - dialog.getDialogPane().getScene().getWindow().sizeToScene(); - 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); + /** + * 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(); - } + 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(); - } + //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 c7866cf..672759b 100644 --- a/src/cl/cromer/estructuras/MenuController.java +++ b/src/cl/cromer/estructuras/MenuController.java @@ -25,352 +25,352 @@ import static cl.cromer.estructuras.ListaEnlazadaTipos.SIMPLE; * Controlar las acciones cuando una opción es elegido en el menu. */ public class MenuController extends VBox implements Initializable { - /** - * La barra del menu. - */ - @FXML - private MenuBar menuBar; + /** + * La barra del menu. + */ + @FXML + private MenuBar menuBar; - /** - * Los idiomas. - */ - private ResourceBundle resourceBundle; + /** + * Los idiomas. + */ + private ResourceBundle resourceBundle; - /** - * Inicialicar el menu con el idioma. - * - * @param location URL: Tiene URL de FXML en uso. - * @param resourceBundle: Tiene los idiomas. - */ - @Override - public void initialize(URL location, ResourceBundle resourceBundle) { - this.resourceBundle = resourceBundle; - } + /** + * Inicialicar el menu con el idioma. + * + * @param location URL: Tiene URL de FXML en uso. + * @param resourceBundle: Tiene los idiomas. + */ + @Override + public void initialize(URL location, ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; + } - /** - * Click en Array Simple. - */ - @FXML - protected void menuArraySimple() { - ArrayTipos arrayTipos = new ArrayTipos(ArrayTipos.SIMPLE); - loadStage( - resourceBundle.getString("tituloArraySimple"), - "/cl/cromer/estructuras/fxml/array.fxml", - "/cl/cromer/estructuras/css/style.css", - arrayTipos - ); - } + /** + * Click en Array Simple. + */ + @FXML + protected void menuArraySimple() { + ArrayTipos arrayTipos = new ArrayTipos(ArrayTipos.SIMPLE); + loadStage( + resourceBundle.getString("tituloArraySimple"), + "/cl/cromer/estructuras/fxml/array.fxml", + "/cl/cromer/estructuras/css/style.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(); + /** + * 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); + openFXML(fxml, scene, stage); - scene.getStylesheets().add(css); - scene.setUserData(object); - stage.setScene(scene); - stage.setTitle(this.resourceBundle.getString("titulo") + " - " + title); - } + 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(); - } - } + 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. - */ - @FXML - protected void menuArrayOrdenado() { - ArrayTipos arrayTipos = new ArrayTipos(ArrayTipos.ORDENADO); - loadStage( - resourceBundle.getString("tituloArrayOrdenado"), - "/cl/cromer/estructuras/fxml/array.fxml", - "/cl/cromer/estructuras/css/style.css", - arrayTipos - ); - } + /** + * Click en Array Ordenado. + */ + @FXML + protected void menuArrayOrdenado() { + ArrayTipos arrayTipos = new ArrayTipos(ArrayTipos.ORDENADO); + loadStage( + resourceBundle.getString("tituloArrayOrdenado"), + "/cl/cromer/estructuras/fxml/array.fxml", + "/cl/cromer/estructuras/css/style.css", + arrayTipos + ); + } - /** - * Click en Burbuja. - */ - @FXML - protected void menuBurbuja() { - loadStage( - resourceBundle.getString("tituloBurbuja"), - "/cl/cromer/estructuras/fxml/burbuja.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Burbuja. + */ + @FXML + protected void menuBurbuja() { + loadStage( + resourceBundle.getString("tituloBurbuja"), + "/cl/cromer/estructuras/fxml/burbuja.fxml", + "/cl/cromer/estructuras/css/style.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(); + /** + * 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); + openFXML(fxml, scene, stage); - scene.getStylesheets().add(css); - stage.setScene(scene); - stage.setTitle(this.resourceBundle.getString("titulo") + " - " + title); - } + scene.getStylesheets().add(css); + stage.setScene(scene); + stage.setTitle(this.resourceBundle.getString("titulo") + " - " + title); + } - /** - * Click en Inserción. - */ - @FXML - protected void menuInsercion() { - loadStage( - resourceBundle.getString("tituloInsercion"), - "/cl/cromer/estructuras/fxml/insercion.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Inserción. + */ + @FXML + protected void menuInsercion() { + loadStage( + resourceBundle.getString("tituloInsercion"), + "/cl/cromer/estructuras/fxml/insercion.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Selecion. - */ - @FXML - protected void menuSeleccion() { - loadStage( - resourceBundle.getString("tituloSeleccion"), - "/cl/cromer/estructuras/fxml/seleccion.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Selecion. + */ + @FXML + protected void menuSeleccion() { + loadStage( + resourceBundle.getString("tituloSeleccion"), + "/cl/cromer/estructuras/fxml/seleccion.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Shell. - */ - @FXML - protected void menuShell() { - loadStage( - resourceBundle.getString("tituloShell"), - "/cl/cromer/estructuras/fxml/shell.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Shell. + */ + @FXML + protected void menuShell() { + loadStage( + resourceBundle.getString("tituloShell"), + "/cl/cromer/estructuras/fxml/shell.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Quick. - */ - @FXML - protected void menuQuick() { - loadStage( - resourceBundle.getString("tituloQuick"), - "/cl/cromer/estructuras/fxml/quick.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Quick. + */ + @FXML + protected void menuQuick() { + loadStage( + resourceBundle.getString("tituloQuick"), + "/cl/cromer/estructuras/fxml/quick.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Merge. - */ - @FXML - protected void menuMerge() { - loadStage( - resourceBundle.getString("tituloMerge"), - "/cl/cromer/estructuras/fxml/merge.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Merge. + */ + @FXML + protected void menuMerge() { + loadStage( + resourceBundle.getString("tituloMerge"), + "/cl/cromer/estructuras/fxml/merge.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Lista Enlazada Simple. - */ - @FXML - protected void menuListaEnlazadaSimple() { - ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(SIMPLE); - loadStage( - resourceBundle.getString("tituloListaEnlazadaSimple"), - "/cl/cromer/estructuras/fxml/listaEnlazada.fxml", - "/cl/cromer/estructuras/css/style.css", - listaEnlazadaTipos - ); - } + /** + * Click en Lista Enlazada Simple. + */ + @FXML + protected void menuListaEnlazadaSimple() { + ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(SIMPLE); + loadStage( + resourceBundle.getString("tituloListaEnlazadaSimple"), + "/cl/cromer/estructuras/fxml/listaEnlazada.fxml", + "/cl/cromer/estructuras/css/style.css", + listaEnlazadaTipos + ); + } - /** - * Click en Lista Enlazada Circular. - */ - @FXML - protected void menuListaEnlazadaCircular() { - ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(ListaEnlazadaTipos.CIRCULAR); - loadStage( - resourceBundle.getString("tituloListaEnlazadaCircular"), - "/cl/cromer/estructuras/fxml/listaEnlazada.fxml", - "/cl/cromer/estructuras/css/style.css", - listaEnlazadaTipos - ); - } + /** + * Click en Lista Enlazada Circular. + */ + @FXML + protected void menuListaEnlazadaCircular() { + ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(ListaEnlazadaTipos.CIRCULAR); + loadStage( + resourceBundle.getString("tituloListaEnlazadaCircular"), + "/cl/cromer/estructuras/fxml/listaEnlazada.fxml", + "/cl/cromer/estructuras/css/style.css", + listaEnlazadaTipos + ); + } - /** - * Click en Lista Enlazada Doble. - */ - @FXML - protected void menuListaEnlazadaDoble() { - ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA); - loadStage( - resourceBundle.getString("tituloListaEnlazadaDoble"), - "/cl/cromer/estructuras/fxml/listaEnlazada.fxml", - "/cl/cromer/estructuras/css/style.css", - listaEnlazadaTipos - ); - } + /** + * Click en Lista Enlazada Doble. + */ + @FXML + protected void menuListaEnlazadaDoble() { + ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA); + loadStage( + resourceBundle.getString("tituloListaEnlazadaDoble"), + "/cl/cromer/estructuras/fxml/listaEnlazada.fxml", + "/cl/cromer/estructuras/css/style.css", + listaEnlazadaTipos + ); + } - /** - * Click en Pila. - */ - @FXML - protected void menuPila() { - loadStage( - resourceBundle.getString("tituloPila"), - "/cl/cromer/estructuras/fxml/pila.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Pila. + */ + @FXML + protected void menuPila() { + loadStage( + resourceBundle.getString("tituloPila"), + "/cl/cromer/estructuras/fxml/pila.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Cola. - */ - @FXML - protected void menuCola() { - loadStage( - resourceBundle.getString("tituloCola"), - "/cl/cromer/estructuras/fxml/cola.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Cola. + */ + @FXML + protected void menuCola() { + loadStage( + resourceBundle.getString("tituloCola"), + "/cl/cromer/estructuras/fxml/cola.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Hash Table. - */ - @FXML - protected void menuHashTable() { - loadStage( - resourceBundle.getString("tituloTablaHash"), - "/cl/cromer/estructuras/fxml/hashTable.fxml", - "/cl/cromer/estructuras/css/style.css" - ); - } + /** + * Click en Hash Table. + */ + @FXML + protected void menuHashTable() { + loadStage( + resourceBundle.getString("tituloTablaHash"), + "/cl/cromer/estructuras/fxml/hashTable.fxml", + "/cl/cromer/estructuras/css/style.css" + ); + } - /** - * Click en Ingles. - */ - @FXML - protected void menuIngles() { - ButtonType botonCambiar = new ButtonType(resourceBundle.getString("cambiar"), ButtonBar.ButtonData.OK_DONE); - ButtonType botonCancelar = new ButtonType(resourceBundle.getString("cancelar"), ButtonBar.ButtonData.CANCEL_CLOSE); - Dialog dialog = new Dialog<>(); - dialog.setTitle(resourceBundle.getString("cambiarIdioma")); - dialog.setContentText(resourceBundle.getString("cambiarIdiomaMensaje")); - dialog.getDialogPane().getButtonTypes().add(botonCancelar); - dialog.getDialogPane().getButtonTypes().add(botonCambiar); - dialog.getDialogPane().getScene().getWindow().sizeToScene(); - Main.setIcon(dialog, getClass()); + /** + * Click en Ingles. + */ + @FXML + protected void menuIngles() { + ButtonType botonCambiar = new ButtonType(resourceBundle.getString("cambiar"), ButtonBar.ButtonData.OK_DONE); + ButtonType botonCancelar = new ButtonType(resourceBundle.getString("cancelar"), ButtonBar.ButtonData.CANCEL_CLOSE); + Dialog dialog = new Dialog<>(); + dialog.setTitle(resourceBundle.getString("cambiarIdioma")); + dialog.setContentText(resourceBundle.getString("cambiarIdiomaMensaje")); + dialog.getDialogPane().getButtonTypes().add(botonCancelar); + dialog.getDialogPane().getButtonTypes().add(botonCambiar); + dialog.getDialogPane().getScene().getWindow().sizeToScene(); + Main.setIcon(dialog, getClass()); - Optional result = dialog.showAndWait(); - if (result.isPresent() && result.get() == botonCambiar) { - // Si hace click en cambiar, cambiar el idioma y reiniciar. - Locale locale = new Locale("en", "EN"); - ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale); + Optional result = dialog.showAndWait(); + if (result.isPresent() && result.get() == botonCambiar) { + // Si hace click en cambiar, cambiar el idioma y reiniciar. + 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( + "/cl/cromer/estructuras/fxml/main.fxml", + "/cl/cromer/estructuras/css/style.css", + 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(); + /** + * 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(); - } + 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")); - } + scene.getStylesheets().add(css); + stage.setScene(scene); + stage.setTitle(resourceBundle.getString("titulo")); + } - /** - * Click en Español. - */ - @FXML - protected void menuEspanol() { - ButtonType botonCambiar = new ButtonType(resourceBundle.getString("cambiar"), ButtonBar.ButtonData.OK_DONE); - ButtonType botonCancelar = new ButtonType(resourceBundle.getString("cancelar"), ButtonBar.ButtonData.CANCEL_CLOSE); - Dialog dialog = new Dialog<>(); - dialog.setTitle(resourceBundle.getString("cambiarIdioma")); - dialog.setContentText(resourceBundle.getString("cambiarIdiomaMensaje")); - dialog.getDialogPane().getButtonTypes().add(botonCancelar); - dialog.getDialogPane().getButtonTypes().add(botonCambiar); - dialog.getDialogPane().getScene().getWindow().sizeToScene(); - Main.setIcon(dialog, getClass()); + /** + * Click en Español. + */ + @FXML + protected void menuEspanol() { + ButtonType botonCambiar = new ButtonType(resourceBundle.getString("cambiar"), ButtonBar.ButtonData.OK_DONE); + ButtonType botonCancelar = new ButtonType(resourceBundle.getString("cancelar"), ButtonBar.ButtonData.CANCEL_CLOSE); + Dialog dialog = new Dialog<>(); + dialog.setTitle(resourceBundle.getString("cambiarIdioma")); + dialog.setContentText(resourceBundle.getString("cambiarIdiomaMensaje")); + dialog.getDialogPane().getButtonTypes().add(botonCancelar); + dialog.getDialogPane().getButtonTypes().add(botonCambiar); + dialog.getDialogPane().getScene().getWindow().sizeToScene(); + Main.setIcon(dialog, getClass()); - Optional result = dialog.showAndWait(); - if (result.isPresent() && result.get() == botonCambiar) { - // Si hace click en cambiar, cambiar el idioma y reiniciar. - Locale locale = new Locale("es", "ES"); - ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale); + Optional result = dialog.showAndWait(); + if (result.isPresent() && result.get() == botonCambiar) { + // Si hace click en cambiar, cambiar el idioma y reiniciar. + 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( + "/cl/cromer/estructuras/fxml/main.fxml", + "/cl/cromer/estructuras/css/style.css", + resourceBundle + ); + } + } - /** - * Click en Acerca. - */ - @FXML - protected void menuAcerca() { - ButtonType botonCerrar = new ButtonType(resourceBundle.getString("cerrar"), ButtonBar.ButtonData.OK_DONE); - Dialog dialog = new Dialog<>(); - dialog.setTitle(resourceBundle.getString("acerca")); - dialog.setContentText(resourceBundle.getString("credito")); - dialog.getDialogPane().getButtonTypes().add(botonCerrar); - dialog.getDialogPane().getScene().getWindow().sizeToScene(); - Main.setIcon(dialog, getClass()); - dialog.show(); - } + /** + * Click en Acerca. + */ + @FXML + protected void menuAcerca() { + ButtonType botonCerrar = new ButtonType(resourceBundle.getString("cerrar"), ButtonBar.ButtonData.OK_DONE); + Dialog dialog = new Dialog<>(); + dialog.setTitle(resourceBundle.getString("acerca")); + dialog.setContentText(resourceBundle.getString("credito")); + dialog.getDialogPane().getButtonTypes().add(botonCerrar); + dialog.getDialogPane().getScene().getWindow().sizeToScene(); + Main.setIcon(dialog, getClass()); + dialog.show(); + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/MergeController.java b/src/cl/cromer/estructuras/MergeController.java index 23d86e7..776205b 100644 --- a/src/cl/cromer/estructuras/MergeController.java +++ b/src/cl/cromer/estructuras/MergeController.java @@ -46,7 +46,7 @@ public class MergeController implements Initializable { /** * Inicializar todos los datos y dibujar las graficas. * - * @param location URL: El URL de fxml en uso. + * @param location URL: El URL de fxml en uso. * @param resourceBundle ResourceBundle: Tiene datos de idioma. */ @Override @@ -112,7 +112,7 @@ public class MergeController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/merge/ordenar")).useDelimiter("\\Z").next(); codigoMerge.setText(codigoTexto); - if (!array.merge(true)) { + if (! array.merge(true)) { Main.mostrarError(resourceBundle.getString("mergeYaOrdenado"), resourceBundle); } @@ -132,10 +132,10 @@ public class MergeController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/merge/ordenar")).useDelimiter("\\Z").next(); codigoMerge.setText(codigoTexto); - if (!array.merge(false)) { + if (! array.merge(false)) { Main.mostrarError(resourceBundle.getString("mergeYaOrdenado"), resourceBundle); } - generarGrafico(); + generarGrafico(); } } diff --git a/src/cl/cromer/estructuras/Palabras.java b/src/cl/cromer/estructuras/Palabras.java index 8e8ed80..e8b24b8 100644 --- a/src/cl/cromer/estructuras/Palabras.java +++ b/src/cl/cromer/estructuras/Palabras.java @@ -5,61 +5,61 @@ import java.util.List; import java.util.Random; public class Palabras { - final private List palabras; + final private List palabras; - public Palabras() { - palabras = new ArrayList<>(); - palabras.add("hola"); - palabras.add("mundo"); - palabras.add("cruel"); - palabras.add("mi"); - palabras.add("tiempo"); - palabras.add("es"); - palabras.add("limitado"); - palabras.add("pero"); - palabras.add("puedo"); - palabras.add("lograr"); - palabras.add("el"); - palabras.add("proyecto"); - palabras.add("si"); - palabras.add("trabajo"); - palabras.add("bien"); - palabras.add("computador"); - palabras.add("test"); - palabras.add("mouse"); - palabras.add("clase"); - palabras.add("software"); - palabras.add("hardware"); - palabras.add("vaso"); - palabras.add("mesa"); - palabras.add("tabla"); - palabras.add("color"); - palabras.add("calor"); - palabras.add("edad"); - palabras.add("olor"); - palabras.add("ganar"); - palabras.add("dormir"); - palabras.add("tomar"); - palabras.add("comer"); - palabras.add("pensar"); - palabras.add("programar"); - palabras.add("hablar"); - palabras.add("sentir"); - palabras.add("perder"); - palabras.add("abrir"); - palabras.add("cerrar"); - palabras.add("mirar"); - palabras.add("agua"); - palabras.add("me"); - palabras.add("llaman"); - palabras.add("gringo"); - palabras.add("loco"); - palabras.add("no"); - } + public Palabras() { + palabras = new ArrayList<>(); + palabras.add("hola"); + palabras.add("mundo"); + palabras.add("cruel"); + palabras.add("mi"); + palabras.add("tiempo"); + palabras.add("es"); + palabras.add("limitado"); + palabras.add("pero"); + palabras.add("puedo"); + palabras.add("lograr"); + palabras.add("el"); + palabras.add("proyecto"); + palabras.add("si"); + palabras.add("trabajo"); + palabras.add("bien"); + palabras.add("computador"); + palabras.add("test"); + palabras.add("mouse"); + palabras.add("clase"); + palabras.add("software"); + palabras.add("hardware"); + palabras.add("vaso"); + palabras.add("mesa"); + palabras.add("tabla"); + palabras.add("color"); + palabras.add("calor"); + palabras.add("edad"); + palabras.add("olor"); + palabras.add("ganar"); + palabras.add("dormir"); + palabras.add("tomar"); + palabras.add("comer"); + palabras.add("pensar"); + palabras.add("programar"); + palabras.add("hablar"); + palabras.add("sentir"); + palabras.add("perder"); + palabras.add("abrir"); + palabras.add("cerrar"); + palabras.add("mirar"); + palabras.add("agua"); + palabras.add("me"); + palabras.add("llaman"); + palabras.add("gringo"); + palabras.add("loco"); + palabras.add("no"); + } - public String getPalabra() { - Random random = new Random(); - int numero = random.nextInt(palabras.size()); - return palabras.get(numero); - } + public String getPalabra() { + Random random = new Random(); + int numero = random.nextInt(palabras.size()); + return palabras.get(numero); + } } diff --git a/src/cl/cromer/estructuras/Pila.java b/src/cl/cromer/estructuras/Pila.java index 87133a6..9a6aa18 100644 --- a/src/cl/cromer/estructuras/Pila.java +++ b/src/cl/cromer/estructuras/Pila.java @@ -8,117 +8,118 @@ import java.util.Random; * @author Chris Cromer */ final public class Pila { - /** - * La pila. - */ - private String pila[]; + /** + * La pila. + */ + private String pila[]; - /** - * La cantidad de elementos en la pila. - */ - private int size; + /** + * La cantidad de elementos en la pila. + */ + private int size; - /** - * Inicializar. - */ - public Pila() { - pila = null; - size = 0; - } + /** + * Inicializar. + */ + public Pila() { + pila = null; + size = 0; + } - /** - * Pop un valor de encima de la pila. - * - * @return boolean: Verdad si fue exitoso. - */ - public boolean pop() { - if (this.pila != null && size() > 0) { - String pila[] = new String[this.pila.length - 1]; - System.arraycopy(this.pila, 0, pila, 0, pila.length); - this.pila = pila; - size--; - return true; - } - else { - return false; - } - } + /** + * Pop un valor de encima de la pila. + * + * @return boolean: Verdad si fue exitoso. + */ + public boolean pop() { + if (this.pila != null && size() > 0) { + String pila[] = new String[this.pila.length - 1]; + System.arraycopy(this.pila, 0, pila, 0, pila.length); + this.pila = pila; + size--; + return true; + } + else { + return false; + } + } - /** - * Devolver la cantidad de elementos en la pila. - * - * @return int: La cantidad de elementos. - */ - public int size() { - return size; - } + /** + * 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. - * - * @return int: El valor que está encima de la pila. - */ - public int peek() { - if (pila != null && size() > 0) { - return Integer.valueOf(pila[pila.length - 1]); - } - else { - return Integer.MIN_VALUE; - } - } + /** + * Peek al valor que está encima de la pila. + * + * @return int: El valor que está encima de la pila. + */ + public int peek() { + if (pila != null && size() > 0) { + return Integer.valueOf(pila[pila.length - 1]); + } + else { + return Integer.MIN_VALUE; + } + } - /** - * Devolver el valor que está en un indice de la pila. - * - * @param indice int: El indice que desea devolver. - * @return String: El valor que está guardado en el indice. - */ - public String getIndice(int indice) { - if (pila != null && indice >= 0 && indice < pila.length) { - return pila[indice]; - } - else { - return null; - } - } + /** + * Devolver el valor que está en un indice de la pila. + * + * @param indice int: El indice que desea devolver. + * + * @return String: El valor que está guardado en el indice. + */ + public String getIndice(int indice) { + if (pila != null && indice >= 0 && indice < pila.length) { + return pila[indice]; + } + else { + return null; + } + } - /** - * Llenar la pila con valores al azar. - */ - @SuppressWarnings("Duplicates") - public void llenar() { - Random random = new Random(); - int maximo = 99; - int minimo = 0; - int rango = maximo - minimo + 1; + /** + * Llenar la pila 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); - } - } + for (int i = size(); i < 10; i++) { + int numero = random.nextInt(rango) + minimo; + 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++; - } - } + /** + * 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 1e7da50..0f60311 100644 --- a/src/cl/cromer/estructuras/PilaController.java +++ b/src/cl/cromer/estructuras/PilaController.java @@ -17,190 +17,190 @@ import java.util.logging.Level; * @author Chris Cromer */ public class PilaController implements Initializable { - /** - * La caja para ingresar textos. - */ - @FXML - private TextFieldLimited valorPila; + /** + * La caja para ingresar textos. + */ + @FXML + private TextFieldLimited valorPila; - /** - * Donde poner el contenido de array. - */ - @FXML - private VBox contenidoPila; + /** + * Donde poner el contenido de array. + */ + @FXML + private VBox contenidoPila; - /** - * Donde va el codigo a mostrar a la pantalla. - */ - @FXML - private Text codigoPila; + /** + * Donde va el codigo a mostrar a la pantalla. + */ + @FXML + private Text codigoPila; - /** - * 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 pila usado en la aplicación. - */ - private Pila pila; + /** + * La pila usado en la aplicación. + */ + private Pila pila; - /** - * 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; - pila = new Pila(); + pila = new Pila(); - scene = null; - Colores colores = new Colores(); + scene = null; + Colores colores = new Colores(); - for (int i = 9; i >= 0; i--) { - contenidoPila.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i))); - colores.siguinteColor(); - } - } + for (int i = 9; i >= 0; i--) { + contenidoPila.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i))); + colores.siguinteColor(); + } + } - /** - * Llenar la pila con numeros al azar. - */ - @FXML - protected void botonLlenar() { - if (scene == null) { - scene = contenidoPila.getScene(); - grafico = new Grafico(scene); - } + /** + * Llenar la pila con numeros al azar. + */ + @FXML + protected void botonLlenar() { + if (scene == null) { + scene = contenidoPila.getScene(); + grafico = new Grafico(scene); + } - pila.llenar(); - generarGrafico(); - } + pila.llenar(); + 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)); - } - } + /** + * 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. - */ - @FXML - protected void botonVaciar() { - if (scene == null) { - scene = contenidoPila.getScene(); - grafico = new Grafico(scene); - } + /** + * Vaciar la pila de todos los valores. + */ + @FXML + protected void botonVaciar() { + if (scene == null) { + scene = contenidoPila.getScene(); + grafico = new Grafico(scene); + } - pila = new Pila(); - generarGrafico(); - } + pila = new Pila(); + generarGrafico(); + } - /** - * Push un valor a la pila y mostrar el codigo en la pantalla. - */ - @FXML - protected void botonPush() { - if (scene == null) { - scene = contenidoPila.getScene(); - grafico = new Grafico(scene); - } + /** + * Push un valor a la pila y mostrar el codigo en la pantalla. + */ + @FXML + protected void botonPush() { + if (scene == null) { + scene = contenidoPila.getScene(); + grafico = new Grafico(scene); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/pila/push")).useDelimiter("\\Z").next(); - codigoPila.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/pila/push")).useDelimiter("\\Z").next(); + codigoPila.setText(codigoTexto); - if (valorPila.getText() != null && !valorPila.getText().trim().equals("")) { - try { - if (pila.size() < 10) { - pila.push(Integer.valueOf(valorPila.getText())); - valorPila.setText(""); - generarGrafico(); - } - else { - Main.mostrarError(resourceBundle.getString("pilaLlena"), resourceBundle); - } - } - catch (NumberFormatException exception) { - // El error no es fatal, sigue - Logs.log(Level.WARNING, "No es tipo int."); - Main.mostrarError(resourceBundle.getString("pilaNoValor"), resourceBundle); - } - } - else { - Main.mostrarError(resourceBundle.getString("pilaNoValor"), resourceBundle); - } - } + if (valorPila.getText() != null && ! valorPila.getText().trim().equals("")) { + try { + if (pila.size() < 10) { + pila.push(Integer.valueOf(valorPila.getText())); + valorPila.setText(""); + generarGrafico(); + } + else { + Main.mostrarError(resourceBundle.getString("pilaLlena"), resourceBundle); + } + } + catch (NumberFormatException exception) { + // El error no es fatal, sigue + Logs.log(Level.WARNING, "No es tipo int."); + Main.mostrarError(resourceBundle.getString("pilaNoValor"), resourceBundle); + } + } + else { + Main.mostrarError(resourceBundle.getString("pilaNoValor"), resourceBundle); + } + } - /** - * Pop un valor de la pila si existe y mostrar el codigo en la pantalla. - */ - @FXML - protected void botonPop() { - if (scene == null) { - scene = contenidoPila.getScene(); - grafico = new Grafico(scene); - } + /** + * Pop un valor de la pila si existe y mostrar el codigo en la pantalla. + */ + @FXML + protected void botonPop() { + if (scene == null) { + scene = contenidoPila.getScene(); + grafico = new Grafico(scene); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/pila/pop")).useDelimiter("\\Z").next(); - codigoPila.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/pila/pop")).useDelimiter("\\Z").next(); + codigoPila.setText(codigoTexto); - if (pila.size() > 0) { - if (!pila.pop()) { - Main.mostrarError(resourceBundle.getString("pilaVacia"), resourceBundle); - } - else { - generarGrafico(); - } - } - else { - Main.mostrarError(resourceBundle.getString("pilaVacia"), resourceBundle); - } - } + if (pila.size() > 0) { + if (! pila.pop()) { + Main.mostrarError(resourceBundle.getString("pilaVacia"), resourceBundle); + } + else { + generarGrafico(); + } + } + else { + Main.mostrarError(resourceBundle.getString("pilaVacia"), resourceBundle); + } + } - /** - * Peek a ver si existe un elemento en la pila y mostrar el codigo en la pantalla - * Si existe un valor destacarlo. - */ - @FXML - protected void botonPeek() { - if (scene == null) { - scene = contenidoPila.getScene(); - grafico = new Grafico(scene); - } + /** + * Peek a ver si existe un elemento en la pila y mostrar el codigo en la pantalla + * Si existe un valor destacarlo. + */ + @FXML + protected void botonPeek() { + if (scene == null) { + scene = contenidoPila.getScene(); + grafico = new Grafico(scene); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/pila/peek")).useDelimiter("\\Z").next(); - codigoPila.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/pila/peek")).useDelimiter("\\Z").next(); + codigoPila.setText(codigoTexto); - int encontrado = pila.peek(); - if (encontrado != Integer.MIN_VALUE) { - generarGrafico(); - grafico.destacar("#caja_" + (pila.size() - 1), Grafico.RECTANGULO); - grafico.destacar("#texto_" + (pila.size() - 1), Grafico.TEXTO); - } - else { - Main.mostrarError(resourceBundle.getString("pilaVacia"), resourceBundle); - } - } + int encontrado = pila.peek(); + if (encontrado != Integer.MIN_VALUE) { + generarGrafico(); + grafico.destacar("#caja_" + (pila.size() - 1), Grafico.RECTANGULO); + grafico.destacar("#texto_" + (pila.size() - 1), Grafico.TEXTO); + } + else { + Main.mostrarError(resourceBundle.getString("pilaVacia"), resourceBundle); + } + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/QuickController.java b/src/cl/cromer/estructuras/QuickController.java index 78f1077..2685e7b 100644 --- a/src/cl/cromer/estructuras/QuickController.java +++ b/src/cl/cromer/estructuras/QuickController.java @@ -46,7 +46,7 @@ public class QuickController implements Initializable { /** * Inicializar todos los datos y dibujar las graficas. * - * @param location URL: El URL de fxml en uso. + * @param location URL: El URL de fxml en uso. * @param resourceBundle ResourceBundle: Tiene datos de idioma. */ @Override @@ -112,7 +112,7 @@ public class QuickController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/quick/ordenar")).useDelimiter("\\Z").next(); codigoQuick.setText(codigoTexto); - if (!array.quick(true)) { + if (! array.quick(true)) { Main.mostrarError(resourceBundle.getString("quickYaOrdenado"), resourceBundle); } @@ -132,10 +132,10 @@ public class QuickController implements Initializable { String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/quick/ordenar")).useDelimiter("\\Z").next(); codigoQuick.setText(codigoTexto); - if (!array.quick(false)) { + if (! array.quick(false)) { Main.mostrarError(resourceBundle.getString("quickYaOrdenado"), resourceBundle); } - generarGrafico(); + generarGrafico(); } } diff --git a/src/cl/cromer/estructuras/SeleccionController.java b/src/cl/cromer/estructuras/SeleccionController.java index ff6803d..2b06a65 100644 --- a/src/cl/cromer/estructuras/SeleccionController.java +++ b/src/cl/cromer/estructuras/SeleccionController.java @@ -16,78 +16,78 @@ import java.util.Scanner; * @author Chris Cromer */ public class SeleccionController implements Initializable { - /** - * Donde poner el contenido de array. - */ - @FXML - private HBox contenidoSeleccion; + /** + * Donde poner el contenido de array. + */ + @FXML + private HBox contenidoSeleccion; - /** - * Donde va el codigo a mostrar a la pantalla. - */ - @FXML - private Text codigoSeleccion; + /** + * Donde va el codigo a mostrar a la pantalla. + */ + @FXML + private Text codigoSeleccion; - /** - * 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++) { - contenidoSeleccion.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i)))); - colores.siguinteColor(); - } - } + for (int i = 0; i < 10; i++) { + contenidoSeleccion.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 = contenidoSeleccion.getScene(); - } + /** + * Crear el array de tamaño 10. + */ + private void initializeScene() { + scene = contenidoSeleccion.getScene(); + } /** * Poner los valores en el grafico. @@ -100,42 +100,42 @@ public class SeleccionController implements Initializable { } /** - * Ordenarlo paso por paso. - */ - @FXML - protected void botonPaso() { - if (scene == null) { - initializeScene(); - } + * 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/seleccion/ordenar")).useDelimiter("\\Z").next(); - codigoSeleccion.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/seleccion/ordenar")).useDelimiter("\\Z").next(); + codigoSeleccion.setText(codigoTexto); - if (!array.seleccion(true)) { - Main.mostrarError(resourceBundle.getString("seleccionYaOrdenado"), resourceBundle); - } + if (! array.seleccion(true)) { + Main.mostrarError(resourceBundle.getString("seleccionYaOrdenado"), resourceBundle); + } - generarGrafico(); - } + generarGrafico(); + } - /** - * Ordenarlo completamente. - */ - @FXML - protected void botonCorrer() { - if (scene == null) { - initializeScene(); - } + /** + * Ordenarlo completamente. + */ + @FXML + protected void botonCorrer() { + if (scene == null) { + initializeScene(); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/seleccion/ordenar")).useDelimiter("\\Z").next(); - codigoSeleccion.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/seleccion/ordenar")).useDelimiter("\\Z").next(); + codigoSeleccion.setText(codigoTexto); - if (!array.seleccion(false)) { - Main.mostrarError(resourceBundle.getString("seleccionYaOrdenado"), resourceBundle); - } + if (! array.seleccion(false)) { + Main.mostrarError(resourceBundle.getString("seleccionYaOrdenado"), resourceBundle); + } - generarGrafico(); - } + generarGrafico(); + } } diff --git a/src/cl/cromer/estructuras/ShellController.java b/src/cl/cromer/estructuras/ShellController.java index cb3baec..3cf279c 100644 --- a/src/cl/cromer/estructuras/ShellController.java +++ b/src/cl/cromer/estructuras/ShellController.java @@ -16,78 +16,78 @@ import java.util.Scanner; * @author Chris Cromer */ public class ShellController implements Initializable { - /** - * Donde poner el contenido de array. - */ - @FXML - private HBox contenidoShell; + /** + * Donde poner el contenido de array. + */ + @FXML + private HBox contenidoShell; - /** - * Donde va el codigo a mostrar a la pantalla. - */ - @FXML - private Text codigoShell; + /** + * Donde va el codigo a mostrar a la pantalla. + */ + @FXML + private Text codigoShell; - /** - * 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++) { - contenidoShell.getChildren().addAll(Grafico.crearCaja(colores, String.valueOf(i), String.valueOf(array.getIndice(i)))); - colores.siguinteColor(); - } - } + for (int i = 0; i < 10; i++) { + contenidoShell.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 = contenidoShell.getScene(); - } + /** + * Crear el array de tamaño 10. + */ + private void initializeScene() { + scene = contenidoShell.getScene(); + } /** * Poner los valores en el grafico. @@ -100,42 +100,42 @@ public class ShellController implements Initializable { } /** - * Ordenarlo paso por paso. - */ - @FXML - protected void botonPaso() { - if (scene == null) { - initializeScene(); - } + * 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/shell/ordenar")).useDelimiter("\\Z").next(); - codigoShell.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/shell/ordenar")).useDelimiter("\\Z").next(); + codigoShell.setText(codigoTexto); - if (!array.shell(true)) { - Main.mostrarError(resourceBundle.getString("shellYaOrdenado"), resourceBundle); - } + if (! array.shell(true)) { + Main.mostrarError(resourceBundle.getString("shellYaOrdenado"), resourceBundle); + } - generarGrafico(); - } + generarGrafico(); + } - /** - * Ordenarlo completamente. - */ - @FXML - protected void botonCorrer() { - if (scene == null) { - initializeScene(); - } + /** + * Ordenarlo completamente. + */ + @FXML + protected void botonCorrer() { + if (scene == null) { + initializeScene(); + } - // Mostrar el codigo - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/shell/ordenar")).useDelimiter("\\Z").next(); - codigoShell.setText(codigoTexto); + // Mostrar el codigo + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/shell/ordenar")).useDelimiter("\\Z").next(); + codigoShell.setText(codigoTexto); - if (!array.shell(false)) { - Main.mostrarError(resourceBundle.getString("shellYaOrdenado"), resourceBundle); - } + if (! array.shell(false)) { + Main.mostrarError(resourceBundle.getString("shellYaOrdenado"), resourceBundle); + } - generarGrafico(); - } + generarGrafico(); + } } diff --git a/src/cl/cromer/estructuras/TextFieldLimited.java b/src/cl/cromer/estructuras/TextFieldLimited.java index f5504ba..36e776b 100644 --- a/src/cl/cromer/estructuras/TextFieldLimited.java +++ b/src/cl/cromer/estructuras/TextFieldLimited.java @@ -19,147 +19,147 @@ import java.util.List; * @author Chris Cromer */ public class TextFieldLimited extends TextField { - /** - * La cantidad maxima de caracters permitidas en el TextFieldLimited - */ - private IntegerProperty maxLength; + /** + * La cantidad maxima de caracters permitidas en el TextFieldLimited + */ + private IntegerProperty maxLength; - /** - * Llamar a TextField. - */ - public TextFieldLimited() { - super(); - } + /** + * Llamar a TextField. + */ + public TextFieldLimited() { + super(); + } - /** - * Lista de estilos aplicable. - * - * @return List: La lista de estilos. - */ - @SuppressWarnings("unused") - public static List> getClassCssMetaData() { - return TextFieldLimited.StyleableProperties.STYLEABLES; - } + /** + * Lista de estilos aplicable. + * + * @return List: La lista de estilos. + */ + @SuppressWarnings("unused") + public static List> getClassCssMetaData() { + return TextFieldLimited.StyleableProperties.STYLEABLES; + } - /** - * Reemplazar el texto basado en cambios de teclado, no deja ingresar mas text si length es mayor al maximo. - * - * @param start int: Donde empece el cambio. - * @param end int: Donde termina. - * @param text String: Texto a cambiar. - */ - @Override - public void replaceText(int start, int end, String text) { - if (getMaxLength() != 0) { - if (text.equals("")) { - super.replaceText(start, end, text); - } - else if (getText().length() < getMaxLength()) { - super.replaceText(start, end, text); - } - } - else { - super.replaceText(start, end, text); - } - } + /** + * Reemplazar el texto basado en cambios de teclado, no deja ingresar mas text si length es mayor al maximo. + * + * @param start int: Donde empece el cambio. + * @param end int: Donde termina. + * @param text String: Texto a cambiar. + */ + @Override + public void replaceText(int start, int end, String text) { + if (getMaxLength() != 0) { + if (text.equals("")) { + super.replaceText(start, end, text); + } + else if (getText().length() < getMaxLength()) { + super.replaceText(start, end, text); + } + } + else { + super.replaceText(start, end, text); + } + } - /** - * Reemplazar un selección de texto. - * - * @param text String: El texto a reemplazar. - */ - @Override - public void replaceSelection(String text) { - if (getMaxLength() != 0) { - if (text.equals("")) { - super.replaceSelection(text); - } - else if (getText().length() < getMaxLength()) { - if (text.length() > getMaxLength() - getText().length()) { - text = text.substring(0, getMaxLength() - getText().length()); - } - super.replaceSelection(text); - } - } - else { - super.replaceSelection(text); - } - } + /** + * Reemplazar un selección de texto. + * + * @param text String: El texto a reemplazar. + */ + @Override + public void replaceSelection(String text) { + if (getMaxLength() != 0) { + if (text.equals("")) { + super.replaceSelection(text); + } + else if (getText().length() < getMaxLength()) { + if (text.length() > getMaxLength() - getText().length()) { + text = text.substring(0, getMaxLength() - getText().length()); + } + super.replaceSelection(text); + } + } + else { + super.replaceSelection(text); + } + } - /** - * Devolver la cantidad maxima si está asignado. - * - * @return int: Cantidad de caracters. - */ - public final int getMaxLength() { - return maxLength == null ? 0 : maxLength.get(); - } + /** + * Devolver la cantidad maxima si está asignado. + * + * @return int: Cantidad de caracters. + */ + public final int getMaxLength() { + return maxLength == null ? 0 : maxLength.get(); + } - /** - * Asignar un valor maximo de caracters permitidio en el TextFieldLimited. - * - * @param value int: La cantidad maxima. - */ - @SuppressWarnings("unused") - public final void setMaxLength(int value) { - if (maxLength != null || value > 0) { - maxLengthProperty().set(value); - } - } + /** + * Asignar un valor maximo de caracters permitidio en el TextFieldLimited. + * + * @param value int: La cantidad maxima. + */ + @SuppressWarnings("unused") + public final void setMaxLength(int value) { + if (maxLength != null || value > 0) { + maxLengthProperty().set(value); + } + } - /** - * JavaFX FXML field property por tamaño maximo - * - * @return IntegerProperty: Property. - */ - public final IntegerProperty maxLengthProperty() { - if (maxLength == null) { - maxLength = new StyleableIntegerProperty() { + /** + * JavaFX FXML field property por tamaño maximo + * + * @return IntegerProperty: Property. + */ + public final IntegerProperty maxLengthProperty() { + if (maxLength == null) { + maxLength = new StyleableIntegerProperty() { - @Override - public CssMetaData getCssMetaData() { - return TextFieldLimited.StyleableProperties.MAX_LENGTH; - } + @Override + public CssMetaData getCssMetaData() { + return TextFieldLimited.StyleableProperties.MAX_LENGTH; + } - @Override - public Object getBean() { - return TextFieldLimited.this; - } + @Override + public Object getBean() { + return TextFieldLimited.this; + } - @Override - public String getName() { - return "maxLength"; - } - }; - } - return maxLength; - } + @Override + public String getName() { + return "maxLength"; + } + }; + } + return maxLength; + } - /** - * CSS por FXML con un maximo tamaño - */ - private static class StyleableProperties { - private static final CssMetaData MAX_LENGTH = - new CssMetaData("-fx-max-length", SizeConverter.getInstance(), 0) { - @Override - public boolean isSettable(TextFieldLimited node) { - return node.maxLength == null || !node.maxLength.isBound(); - } + /** + * CSS por FXML con un maximo tamaño + */ + private static class StyleableProperties { + private static final CssMetaData MAX_LENGTH = + new CssMetaData("-fx-max-length", SizeConverter.getInstance(), 0) { + @Override + public boolean isSettable(TextFieldLimited node) { + return node.maxLength == null || ! node.maxLength.isBound(); + } - @Override - @SuppressWarnings("unchecked") - public StyleableProperty getStyleableProperty(TextFieldLimited node) { - return (StyleableProperty) node.maxLengthProperty(); - } + @Override + @SuppressWarnings("unchecked") + public StyleableProperty getStyleableProperty(TextFieldLimited node) { + return (StyleableProperty) node.maxLengthProperty(); + } - }; + }; - private static final List> STYLEABLES; + private static final List> STYLEABLES; - static { - final List> styleables = new ArrayList<>(Shape.getClassCssMetaData()); - styleables.add(MAX_LENGTH); - STYLEABLES = Collections.unmodifiableList(styleables); - } - } + static { + final List> styleables = new ArrayList<>(Shape.getClassCssMetaData()); + styleables.add(MAX_LENGTH); + STYLEABLES = Collections.unmodifiableList(styleables); + } + } } diff --git a/src/cl/cromer/estructuras/code/arrayOrdenado/buscar b/src/cl/cromer/estructuras/code/arrayOrdenado/buscar index d0131e7..e9a9b84 100644 --- a/src/cl/cromer/estructuras/code/arrayOrdenado/buscar +++ b/src/cl/cromer/estructuras/code/arrayOrdenado/buscar @@ -1,10 +1,10 @@ public int buscar(int valor) { - for (int i = 0; i < array.length; i++) { - if (array[i] != 0 && array[i] == valor) { - // Se encontró - return i; - } - } - // No se encontró - return -1; + for (int i = 0; i < array.length; i++) { + if (array[i] != 0 && array[i] == valor) { + // Se encontró + return i; + } + } + // No se encontró + return -1; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/arrayOrdenado/eliminar b/src/cl/cromer/estructuras/code/arrayOrdenado/eliminar index be88b41..0fee4e7 100644 --- a/src/cl/cromer/estructuras/code/arrayOrdenado/eliminar +++ b/src/cl/cromer/estructuras/code/arrayOrdenado/eliminar @@ -1,18 +1,18 @@ public boolean eliminar(int valor) { - boolean borrado = false; - for (int i = 0; i < array.length; i++) { - if (array[i] != 0 && array[i] == valor) { - // Eliminar el valor - array[i] = 0; - borrado=true; - for (int j = i; j < array.length; j++) { - if (j != array.length - 1) { - // Correr la array hacia arriba - array[j] = array[j + 1]; - } - } - array[array.length-1] = 0; - } - } - return borrado; + boolean borrado = false; + for (int i = 0; i < array.length; i++) { + if (array[i] != 0 && array[i] == valor) { + // Eliminar el valor + array[i] = 0; + borrado=true; + for (int j = i; j < array.length; j++) { + if (j != array.length - 1) { + // Correr la array hacia arriba + array[j] = array[j + 1]; + } + } + array[array.length-1] = 0; + } + } + return borrado; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/arrayOrdenado/insertar b/src/cl/cromer/estructuras/code/arrayOrdenado/insertar index 318dd33..ff07d4d 100644 --- a/src/cl/cromer/estructuras/code/arrayOrdenado/insertar +++ b/src/cl/cromer/estructuras/code/arrayOrdenado/insertar @@ -1,13 +1,13 @@ public boolean insertar(int valor) { - for (int i = 0; i < array.length; i++) { - if (array[i] == 0) { - array[i] = valor; - return true; - } - else if (array[i] == valor) { - // Ya existe el valor en el array - return false; - } - } - return false; + for (int i = 0; i < array.length; i++) { + if (array[i] == 0) { + array[i] = valor; + return true; + } + else if (array[i] == valor) { + // Ya existe el valor en el array + return false; + } + } + return false; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/arraySimple/buscar b/src/cl/cromer/estructuras/code/arraySimple/buscar index d0131e7..e9a9b84 100644 --- a/src/cl/cromer/estructuras/code/arraySimple/buscar +++ b/src/cl/cromer/estructuras/code/arraySimple/buscar @@ -1,10 +1,10 @@ public int buscar(int valor) { - for (int i = 0; i < array.length; i++) { - if (array[i] != 0 && array[i] == valor) { - // Se encontró - return i; - } - } - // No se encontró - return -1; + for (int i = 0; i < array.length; i++) { + if (array[i] != 0 && array[i] == valor) { + // Se encontró + return i; + } + } + // No se encontró + return -1; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/arraySimple/eliminar b/src/cl/cromer/estructuras/code/arraySimple/eliminar index f41b04d..7a6e30a 100644 --- a/src/cl/cromer/estructuras/code/arraySimple/eliminar +++ b/src/cl/cromer/estructuras/code/arraySimple/eliminar @@ -1,12 +1,12 @@ public boolean eliminar(int valor) { - boolean borrado = false; - for (int i = 0; i < array.length; i++) { - if (array[i] != 0 && array[i] == valor) { - // Eliminar el valor - array[i] = 0; - borrado=true; - break; - } - } - return borrado; + boolean borrado = false; + for (int i = 0; i < array.length; i++) { + if (array[i] != 0 && array[i] == valor) { + // Eliminar el valor + array[i] = 0; + borrado=true; + break; + } + } + return borrado; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/arraySimple/insertar b/src/cl/cromer/estructuras/code/arraySimple/insertar index 318dd33..ff07d4d 100644 --- a/src/cl/cromer/estructuras/code/arraySimple/insertar +++ b/src/cl/cromer/estructuras/code/arraySimple/insertar @@ -1,13 +1,13 @@ public boolean insertar(int valor) { - for (int i = 0; i < array.length; i++) { - if (array[i] == 0) { - array[i] = valor; - return true; - } - else if (array[i] == valor) { - // Ya existe el valor en el array - return false; - } - } - return false; + for (int i = 0; i < array.length; i++) { + if (array[i] == 0) { + array[i] = valor; + return true; + } + else if (array[i] == valor) { + // Ya existe el valor en el array + return false; + } + } + return false; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/burbuja/ordenar b/src/cl/cromer/estructuras/code/burbuja/ordenar index b4d2136..468f7a8 100644 --- a/src/cl/cromer/estructuras/code/burbuja/ordenar +++ b/src/cl/cromer/estructuras/code/burbuja/ordenar @@ -1,13 +1,13 @@ public void burbuja() { - for (int i = elementos - 1; i > 1; i--) { - for(j = 0; in < i; j++) { - // Si están fuera del orden - if (array[j] > array[j+1]) { - // Intercambiar valores - int temp = array[j]; - array[j] = array[j+1]; - array[j+1] = temp; - } - } - } + for (int i = elementos - 1; i > 1; i--) { + for(j = 0; in < i; j++) { + // Si están fuera del orden + if (array[j] > array[j+1]) { + // Intercambiar valores + int temp = array[j]; + array[j] = array[j+1]; + array[j+1] = temp; + } + } + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/cola/peek b/src/cl/cromer/estructuras/code/cola/peek index 0854454..7de4dec 100644 --- a/src/cl/cromer/estructuras/code/cola/peek +++ b/src/cl/cromer/estructuras/code/cola/peek @@ -1,4 +1,4 @@ public int peek() { - // Devolver el valor en el primer indice - return this.pila[primer]; + // Devolver el valor en el primer indice + return this.pila[primer]; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/cola/pop b/src/cl/cromer/estructuras/code/cola/pop index 3ba1e45..e372f03 100644 --- a/src/cl/cromer/estructuras/code/cola/pop +++ b/src/cl/cromer/estructuras/code/cola/pop @@ -1,6 +1,6 @@ public void pop() { - // Borrar el valor que está al prinicipio. - this.pila[primer] = 0; - // Cambiar el primer nivel de la cola. - primer++; + // Borrar el valor que está al prinicipio. + this.pila[primer] = 0; + // Cambiar el primer nivel de la cola. + primer++; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/cola/push b/src/cl/cromer/estructuras/code/cola/push index c453fda..b280416 100644 --- a/src/cl/cromer/estructuras/code/cola/push +++ b/src/cl/cromer/estructuras/code/cola/push @@ -1,6 +1,6 @@ public void push(int valor) { - // Sumar el final. - final++; - // Insertar el valor - this.pila[final] = valor; + // Sumar el final. + final++; + // Insertar el valor + this.pila[final] = valor; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/insercion/ordenar b/src/cl/cromer/estructuras/code/insercion/ordenar index 0c7eaaf..c7d8340 100644 --- a/src/cl/cromer/estructuras/code/insercion/ordenar +++ b/src/cl/cromer/estructuras/code/insercion/ordenar @@ -1,14 +1,14 @@ public void insercion() { - for (int i = 1; i < elementos; i++) { - // Guardar el elemento en un variable temporario. - int temp = array[i]; - int j = i; - // Mover los valores hasta que hay una mas pequeño. - while (j > 0 && array[j-1] >= temp) { - array[j] = array[j-1]; - --j; - } - // Poner el valor temporario despues de los valores mas pequeños. - array[j] = temp; - } + for (int i = 1; i < elementos; i++) { + // Guardar el elemento en un variable temporario. + int temp = array[i]; + int j = i; + // Mover los valores hasta que hay una mas pequeño. + while (j > 0 && array[j-1] >= temp) { + array[j] = array[j-1]; + --j; + } + // Poner el valor temporario despues de los valores mas pequeños. + array[j] = temp; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaCircular/buscar b/src/cl/cromer/estructuras/code/listaEnlazadaCircular/buscar index 72ed5a8..1bdddb1 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaCircular/buscar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaCircular/buscar @@ -1,47 +1,47 @@ 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 < elementos) { - // Buscar hasta la llave es encontrado - lista = lista.getSiguente(); - i++; - } + if (this.primer != null) { + // La lista no es vacia + Enlace lista = this.primer; + int i = 0; + while (lista.getLlave() != llave && i < elementos) { + // Buscar hasta la llave es encontrado + lista = lista.getSiguente(); + i++; + } - if (lista.getLlave() == llave) { - // Devoler el enlace encontrado. - return lista; - } - else { - // No se encontró. - return null; - } - } - else { - // La lista es vacia, devolver null - return null; - } + if (lista.getLlave() == llave) { + // Devoler el enlace encontrado. + return lista; + } + else { + // No se encontró. + return null; + } + } + else { + // La lista es vacia, devolver null + return null; + } } final public class Enlace { - private int llave; - private Enlace siguente; + private int llave; + private Enlace siguente; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaCircular/eliminar b/src/cl/cromer/estructuras/code/listaEnlazadaCircular/eliminar index 4df2940..6c91edb 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaCircular/eliminar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaCircular/eliminar @@ -1,57 +1,57 @@ public void eliminar(int llave) { - if (primer != null) { - // Crear una lista temporario para trabajar - Enlace lista = this.primer; - // Guardar el enlace previo - Enlace previo = lista; - // Solo busca mientras que i es menor que la cantidad de enlaces - int i = 0; - while (lista.getLlave() != llave && i < elementos) { - // Buscar hasta la llave es encontraddo - if (lista.getSiguente() != null) { - // Buscar en el sigenute enlace - previo = lista; - lista = lista.getSiguente(); - } - i++ - } + if (primer != null) { + // Crear una lista temporario para trabajar + Enlace lista = this.primer; + // Guardar el enlace previo + Enlace previo = lista; + // Solo busca mientras que i es menor que la cantidad de enlaces + int i = 0; + while (lista.getLlave() != llave && i < elementos) { + // Buscar hasta la llave es encontraddo + if (lista.getSiguente() != null) { + // Buscar en el sigenute enlace + previo = lista; + lista = lista.getSiguente(); + } + i++ + } - if (lista.getLlave != llave) { - // No se encontró - return; - } + if (lista.getLlave != llave) { + // No se encontró + return; + } - // Se encontró - if (lista == this.lista) { - // Si es el primer enlace, cambiarlo al siguente enlace - this.lista = this.lista.getSiguente(); - } - else { - // Sino cortar este enlace de la lista - previo.setSiguente(lista.getSiguente()); - } - elementos--; - } + // Se encontró + if (lista == this.lista) { + // Si es el primer enlace, cambiarlo al siguente enlace + this.lista = this.lista.getSiguente(); + } + else { + // Sino cortar este enlace de la lista + previo.setSiguente(lista.getSiguente()); + } + elementos--; + } } final public class Enlace { - private int llave; - private Enlace siguente; + private int llave; + private Enlace siguente; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaCircular/insertar b/src/cl/cromer/estructuras/code/listaEnlazadaCircular/insertar index f5ffca7..fbb9445 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaCircular/insertar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaCircular/insertar @@ -1,39 +1,39 @@ public void insertar(int llave) { - if (buscar(llave) == null) { - // Crear un enlace nuevo - Enlace nuevo = new Enlace(primer, llave); + if (buscar(llave) == null) { + // Crear un enlace nuevo + Enlace nuevo = new Enlace(primer, llave); - if (primer == null) { - // Si el primer enlace es null, el ul - ultimo = nuevo; - } + if (primer == null) { + // Si el primer enlace es null, el ul + ultimo = nuevo; + } - // El primer es el nuevo. - primer = nuevo; - // El ultimo apunta al primer. - ultimo.setSiguente(primer); - elementos++; - } + // El primer es el nuevo. + primer = nuevo; + // El ultimo apunta al primer. + ultimo.setSiguente(primer); + elementos++; + } } final public class Enlace { - private int llave; - private Enlace siguente; + private int llave; + private Enlace siguente; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaDoble/buscar b/src/cl/cromer/estructuras/code/listaEnlazadaDoble/buscar index 7074d01..2ea0b8d 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaDoble/buscar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaDoble/buscar @@ -1,54 +1,54 @@ 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 encontraddo - if (lista.getSiguente() != null) { - // Buscar en el sigenute enlace - lista = lista.getSiguente(); - } - else { - // No se encuentra - return null; - } - } - // Se encontró, devolver el enlace - return lista; - } - else { - // La lista es vacia, devolver null - return null; - } + if (this.lista != null) { + // La lista no es vacia + Enlace lista = this.lista; + while (lista.getLlave() != llave) { + // Buscar hasta la llave es encontraddo + if (lista.getSiguente() != null) { + // Buscar en el sigenute enlace + lista = lista.getSiguente(); + } + else { + // No se encuentra + return null; + } + } + // Se encontró, devolver el enlace + return lista; + } + else { + // La lista es vacia, devolver null + return null; + } } final public class Enlace { - private int llave; - private Enlace siguente; - private Enlace previo; + private int llave; + private Enlace siguente; + private Enlace previo; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } - public Enlace getPrevio() { - return previo; - } + public Enlace getPrevio() { + return previo; + } - public void setPrevio(Enlace previo) { - this.previo = previo; - } + public void setPrevio(Enlace previo) { + this.previo = previo; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaDoble/eliminar b/src/cl/cromer/estructuras/code/listaEnlazadaDoble/eliminar index f5069e3..e8cacd3 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaDoble/eliminar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaDoble/eliminar @@ -1,63 +1,63 @@ public void eliminar(int llave) { - if (lista != null) { - // Crear una lista temporario para trabajar - Enlace lista = this.lista; - // Guardar el enlace previo - Enlace previo = lista; - while (lista.getLlave() != llave) { - // Buscar hasta la llave es encontraddo - if (lista.getSiguente() != null) { - // Buscar en el sigenute enlace - previo = lista; - lista = lista.getSiguente(); - } - else { - // No se encuentra la llave - return; - } - } - // Se encontró - if (lista == this.lista) { - // Si es el primer enlace, cambiarlo al siguente enlace - this.lista = this.lista.getSiguente(); - if (this.lista.getPrevio() != null) { - this.lista.setPrevio(null); - } - } - else { - // Sino cortar este enlace de la lista - previo.setSiguente(lista.getSiguente()); - } - } + if (lista != null) { + // Crear una lista temporario para trabajar + Enlace lista = this.lista; + // Guardar el enlace previo + Enlace previo = lista; + while (lista.getLlave() != llave) { + // Buscar hasta la llave es encontraddo + if (lista.getSiguente() != null) { + // Buscar en el sigenute enlace + previo = lista; + lista = lista.getSiguente(); + } + else { + // No se encuentra la llave + return; + } + } + // Se encontró + if (lista == this.lista) { + // Si es el primer enlace, cambiarlo al siguente enlace + this.lista = this.lista.getSiguente(); + if (this.lista.getPrevio() != null) { + this.lista.setPrevio(null); + } + } + else { + // Sino cortar este enlace de la lista + previo.setSiguente(lista.getSiguente()); + } + } } final public class Enlace { - private int llave; - private Enlace siguente; - private Enlace previo; + private int llave; + private Enlace siguente; + private Enlace previo; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } - public Enlace getPrevio() { - return previo; - } + public Enlace getPrevio() { + return previo; + } - public void setPrevio(Enlace previo) { - this.previo = previo; - } + public void setPrevio(Enlace previo) { + this.previo = previo; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaDoble/insertar b/src/cl/cromer/estructuras/code/listaEnlazadaDoble/insertar index 504af8b..58ca44b 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaDoble/insertar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaDoble/insertar @@ -1,43 +1,43 @@ public void insertar(int llave) { - if (buscar(llave) == null) { - // Crear un enlace nuevo - Enlace nuevo = new Enlace(lista, llave); - if (lista != null) { - // El previo es el nuevo. - lista.setPrevio(nuevo); - } - // Agregar el enlace a la lista - lista = nuevo; - } + if (buscar(llave) == null) { + // Crear un enlace nuevo + Enlace nuevo = new Enlace(lista, llave); + if (lista != null) { + // El previo es el nuevo. + lista.setPrevio(nuevo); + } + // Agregar el enlace a la lista + lista = nuevo; + } } final public class Enlace { - private int llave; - private Enlace siguente; - private Enlace previo; + private int llave; + private Enlace siguente; + private Enlace previo; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } - public Enlace getPrevio() { - return previo; - } + public Enlace getPrevio() { + return previo; + } - public void setPrevio(Enlace previo) { - this.previo = previo; - } + public void setPrevio(Enlace previo) { + this.previo = previo; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaSimple/buscar b/src/cl/cromer/estructuras/code/listaEnlazadaSimple/buscar index c0bf7a4..a053358 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaSimple/buscar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaSimple/buscar @@ -1,45 +1,45 @@ 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 encontraddo - if (lista.getSiguente() != null) { - // Buscar en el sigenute enlace - lista = lista.getSiguente(); - } - else { - // No se encuentra - return null; - } - } - // Se encontró, devolver el enlace - return lista; - } - else { - // La lista es vacia, devolver null - return null; - } + if (this.lista != null) { + // La lista no es vacia + Enlace lista = this.lista; + while (lista.getLlave() != llave) { + // Buscar hasta la llave es encontraddo + if (lista.getSiguente() != null) { + // Buscar en el sigenute enlace + lista = lista.getSiguente(); + } + else { + // No se encuentra + return null; + } + } + // Se encontró, devolver el enlace + return lista; + } + else { + // La lista es vacia, devolver null + return null; + } } final public class Enlace { - private int llave; - private Enlace siguente; + private int llave; + private Enlace siguente; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaSimple/eliminar b/src/cl/cromer/estructuras/code/listaEnlazadaSimple/eliminar index 4c7551b..aee9fc7 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaSimple/eliminar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaSimple/eliminar @@ -1,51 +1,51 @@ public void eliminar(int llave) { - if (lista != null) { - // Crear una lista temporario para trabajar - Enlace lista = this.lista; - // Guardar el enlace previo - Enlace previo = lista; - while (lista.getLlave() != llave) { - // Buscar hasta la llave es encontraddo - if (lista.getSiguente() != null) { - // Buscar en el sigenute enlace - previo = lista; - lista = lista.getSiguente(); - } - else { - // No se encuentra la llave - return; - } - } - // Se encontró - if (lista == this.lista) { - // Si es el primer enlace, cambiarlo al siguente enlace - this.lista = this.lista.getSiguente(); - } - else { - // Sino cortar este enlace de la lista - previo.setSiguente(lista.getSiguente()); - } - } + if (lista != null) { + // Crear una lista temporario para trabajar + Enlace lista = this.lista; + // Guardar el enlace previo + Enlace previo = lista; + while (lista.getLlave() != llave) { + // Buscar hasta la llave es encontraddo + if (lista.getSiguente() != null) { + // Buscar en el sigenute enlace + previo = lista; + lista = lista.getSiguente(); + } + else { + // No se encuentra la llave + return; + } + } + // Se encontró + if (lista == this.lista) { + // Si es el primer enlace, cambiarlo al siguente enlace + this.lista = this.lista.getSiguente(); + } + else { + // Sino cortar este enlace de la lista + previo.setSiguente(lista.getSiguente()); + } + } } final public class Enlace { - private int llave; - private Enlace siguente; + private int llave; + private Enlace siguente; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/listaEnlazadaSimple/insertar b/src/cl/cromer/estructuras/code/listaEnlazadaSimple/insertar index 8ae5fc2..2187195 100644 --- a/src/cl/cromer/estructuras/code/listaEnlazadaSimple/insertar +++ b/src/cl/cromer/estructuras/code/listaEnlazadaSimple/insertar @@ -1,30 +1,30 @@ public void insertar(int llave) { - if (buscar(llave) == null) { - // Crear un enlace nuevo - Enlace nuevo = new Enlace(lista, llave); - // Agregar el enlace a la lista - lista = nuevo; - } + if (buscar(llave) == null) { + // Crear un enlace nuevo + Enlace nuevo = new Enlace(lista, llave); + // Agregar el enlace a la lista + lista = nuevo; + } } final public class Enlace { - private int llave; - private Enlace siguente; + private int llave; + private Enlace siguente; - public Enlace(Enlace siguiente, int llave) { - this.siguente = siguente; - this.llave = llave; - } + public Enlace(Enlace siguiente, int llave) { + this.siguente = siguente; + this.llave = llave; + } - public int getLlave() { - return llave; - } + public int getLlave() { + return llave; + } - public Enlace getSiguente() { - return siguente; - } + public Enlace getSiguente() { + return siguente; + } - public void setSiguente(Enlace siguente) { - this.siguente = siguente; - } + public void setSiguente(Enlace siguente) { + this.siguente = siguente; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/merge/ordenar b/src/cl/cromer/estructuras/code/merge/ordenar index 7aa9c3c..e525073 100644 --- a/src/cl/cromer/estructuras/code/merge/ordenar +++ b/src/cl/cromer/estructuras/code/merge/ordenar @@ -1,50 +1,50 @@ public void merge() { - // Crear un array temporario para trabajar. - int[] temp = new int[elementos]; - // Llamar al metodo recursivo. - recMergeSort(temp, 0, elementos - 1); + // Crear un array temporario para trabajar. + int[] temp = new int[elementos]; + // Llamar al metodo recursivo. + recMergeSort(temp, 0, elementos - 1); } private void recMergeSort(int[] temp, int izquerda, int derecha) { - if (izquerda != derecha) { - int medio = (izquerda + derecha) / 2; - // Trabajar con los valores en el lado izquerdo. - recMergeSort(temp, izquerda, medio); - // Trabajar con los valores en el lado derecha. - recMergeSort(temp, medio + 1, derecha); - // Unir los valores. - merge(temp, izquerda, medio + 1, derecha); - } + if (izquerda != derecha) { + int medio = (izquerda + derecha) / 2; + // Trabajar con los valores en el lado izquerdo. + recMergeSort(temp, izquerda, medio); + // Trabajar con los valores en el lado derecha. + recMergeSort(temp, medio + 1, derecha); + // Unir los valores. + merge(temp, izquerda, medio + 1, derecha); + } } private void merge(int[] temp, int prevIzquerda, int prevMedio, int derecha) { - int j = 0; - int izquerda = prevIzquerda; - int medio = prevMedio - 1; - int masDerecha = derecha - izquerda + 1; + int j = 0; + int izquerda = prevIzquerda; + int medio = prevMedio - 1; + int masDerecha = derecha - izquerda + 1; - while (prevIzquerda <= medio && prevMedio <= derecha) { - // Poner un valor en el array temporario. - if (array[prevIzquerda] < array[prevMedio]) { - temp[j++] = array[prevIzquerda++]; - } - else { - temp[j++] = array[prevMedio++]; - } - } + while (prevIzquerda <= medio && prevMedio <= derecha) { + // Poner un valor en el array temporario. + if (array[prevIzquerda] < array[prevMedio]) { + temp[j++] = array[prevIzquerda++]; + } + else { + temp[j++] = array[prevMedio++]; + } + } - while (prevIzquerda <= medio) { - // Mientras que el valor previos de izquerda es menor que el medio correr los valores. - temp[j++] = array[prevIzquerda++]; - } + while (prevIzquerda <= medio) { + // Mientras que el valor previos de izquerda es menor que el medio correr los valores. + temp[j++] = array[prevIzquerda++]; + } - while (prevMedio <= derecha) { - // Mientras que el valor previos de derecha es menor que el medio correr los valores. - temp[j++] = array[prevMedio++]; - } + while (prevMedio <= derecha) { + // Mientras que el valor previos de derecha es menor que el medio correr los valores. + temp[j++] = array[prevMedio++]; + } - for (j = 0; j < masDerecha; j++) { - // Copiar los valores al array real. - array[izquerda + j] = temp[j]; - } + for (j = 0; j < masDerecha; j++) { + // Copiar los valores al array real. + array[izquerda + j] = temp[j]; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/pila/peek b/src/cl/cromer/estructuras/code/pila/peek index 0dcd790..8a27c51 100644 --- a/src/cl/cromer/estructuras/code/pila/peek +++ b/src/cl/cromer/estructuras/code/pila/peek @@ -1,4 +1,4 @@ public int peek() { - // Devolver el valor encima - return this.pila[encima]; + // Devolver el valor encima + return this.pila[encima]; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/pila/pop b/src/cl/cromer/estructuras/code/pila/pop index 97dbfe4..6d47451 100644 --- a/src/cl/cromer/estructuras/code/pila/pop +++ b/src/cl/cromer/estructuras/code/pila/pop @@ -1,6 +1,6 @@ public void pop() { - // Borrar el valor que está encima. - this.pila[encima] = 0; - // Restar el nivel de la pila. - encima--; + // Borrar el valor que está encima. + this.pila[encima] = 0; + // Restar el nivel de la pila. + encima--; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/pila/push b/src/cl/cromer/estructuras/code/pila/push index 375870a..e286f4a 100644 --- a/src/cl/cromer/estructuras/code/pila/push +++ b/src/cl/cromer/estructuras/code/pila/push @@ -1,6 +1,6 @@ public void push(int valor) { - // Sumar el nivel de la pila - encima++; - // Insertar el valor - this.pila[encima] = valor; + // Sumar el nivel de la pila + encima++; + // Insertar el valor + this.pila[encima] = valor; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/quick/ordenar b/src/cl/cromer/estructuras/code/quick/ordenar index 25bf6f1..b0f2324 100644 --- a/src/cl/cromer/estructuras/code/quick/ordenar +++ b/src/cl/cromer/estructuras/code/quick/ordenar @@ -1,47 +1,47 @@ public void quick() { - // Llamar al metodo recursivo. - recurenciaQuick(0, elementos - 1); + // Llamar al metodo recursivo. + recurenciaQuick(0, elementos - 1); } private void recurenciaQuick(int izquerda, int derecha) { - if (derecha - izquerda <= 0) { - // Si derecha es menor que izquerda ya terminó. - return; - } - else { - int pivot = array[derecha]; + if (derecha - izquerda <= 0) { + // Si derecha es menor que izquerda ya terminó. + return; + } + else { + int pivot = array[derecha]; - int particion = particionar(izquerda, derecha, pivot); - recurenciaQuick(izquerda, particion - 1); - recurenciaQuick(particion + 1, derecha); - } + int particion = particionar(izquerda, derecha, pivot); + recurenciaQuick(izquerda, particion - 1); + recurenciaQuick(particion + 1, derecha); + } } private int particionar(int izquerda, int derecha, int pivot) { - int punteroIzquerda = izquerda-1; - int punteroDerecha = derecha; - while (true) { - // Sumar el punteroIzquerda hasta que es igual al pivot - while (array[++punteroIzquerda] < pivot); - // Restar el puntoDerecha hasta que es igual a pivot o hasta 0. - while (punteroDerecha > 0 && array[--punteroDerecha] > pivot); + int punteroIzquerda = izquerda-1; + int punteroDerecha = derecha; + while (true) { + // Sumar el punteroIzquerda hasta que es igual al pivot + while (array[++punteroIzquerda] < pivot); + // Restar el puntoDerecha hasta que es igual a pivot o hasta 0. + while (punteroDerecha > 0 && array[--punteroDerecha] > pivot); - if (punteroIzquerda >= punteroDerecha) { - // Si el puntero izquerda es mayor o igual a la derech termina el while. - break; - } - else { - // Intercambiar los valores. - int temp = array[punteroIzquerda]; - array[punteroIzquerda] = array[punteroDerecha]; - array[punteroDerecha] = temp; - } - } - // Intercambiar los valores. - int temp = array[punteroIzquerda]; - array[punteroIzquerda] = array[derecha]; - array[derecha] = temp; + if (punteroIzquerda >= punteroDerecha) { + // Si el puntero izquerda es mayor o igual a la derech termina el while. + break; + } + else { + // Intercambiar los valores. + int temp = array[punteroIzquerda]; + array[punteroIzquerda] = array[punteroDerecha]; + array[punteroDerecha] = temp; + } + } + // Intercambiar los valores. + int temp = array[punteroIzquerda]; + array[punteroIzquerda] = array[derecha]; + array[derecha] = temp; - // Devolver la posición donde terminó. - return punteroIzquerda; + // Devolver la posición donde terminó. + return punteroIzquerda; } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/seleccion/ordenar b/src/cl/cromer/estructuras/code/seleccion/ordenar index c5b646f..b31c46b 100644 --- a/src/cl/cromer/estructuras/code/seleccion/ordenar +++ b/src/cl/cromer/estructuras/code/seleccion/ordenar @@ -1,13 +1,13 @@ public void seleccion() { - for (int i = 0; i < elementos - 1; i++) { - int minimo = i; - for (int j = i + 1; j < elementos; j++) { - if (array[j] < array[minimo]) { - minimo = j; - } - } - int temp = array[i]; - array[i] = array[minimo]; - array[minimo] = temp; - } + for (int i = 0; i < elementos - 1; i++) { + int minimo = i; + for (int j = i + 1; j < elementos; j++) { + if (array[j] < array[minimo]) { + minimo = j; + } + } + int temp = array[i]; + array[i] = array[minimo]; + array[minimo] = temp; + } } \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/shell/ordenar b/src/cl/cromer/estructuras/code/shell/ordenar index d573346..d4af56e 100644 --- a/src/cl/cromer/estructuras/code/shell/ordenar +++ b/src/cl/cromer/estructuras/code/shell/ordenar @@ -1,25 +1,25 @@ public void shell() { - int i, j; - int temp; + int i, j; + int temp; - int h = 1; - while (h <= elementos / 3) { - // Sumatorio de (h * 3 + 1) - h = h * 3 + 1; - } + int h = 1; + while (h <= elementos / 3) { + // Sumatorio de (h * 3 + 1) + h = h * 3 + 1; + } - // Mientras que h es mayor que 0. - while (h > 0) { - for (i = h; i < elementos; i++) { - temp = array[i]; - j = i; - while (j > h-1 && array[j-h] >= temp) { - // Ordenar dento el "shell" - array[j] = array[j-h]; - j -= h; - } - array[j] = temp; - } - h = (h-1) / 3; - } + // Mientras que h es mayor que 0. + while (h > 0) { + for (i = h; i < elementos; i++) { + temp = array[i]; + j = i; + while (j > h-1 && array[j-h] >= temp) { + // Ordenar dento el "shell" + array[j] = array[j-h]; + j -= h; + } + array[j] = temp; + } + h = (h-1) / 3; + } } \ No newline at end of file