Created
December 26, 2019 06:23
-
-
Save parzibyte/30a07f94a93bac9a0bcb5c94bb8459d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void burbuja(String[] arreglo) { | |
for (int x = 0; x < arreglo.length; x++) { | |
// Aquí "y" se detiene antes de llegar | |
// a length - 1 porque dentro del for, accedemos | |
// al siguiente elemento con el índice actual + 1 | |
for (int y = 0; y < arreglo.length - 1; y++) { | |
String elementoActual = arreglo[y], | |
elementoSiguiente = arreglo[y + 1]; | |
if (elementoActual.compareTo(elementoSiguiente) > 0) { | |
// Intercambiar | |
arreglo[y] = elementoSiguiente; | |
arreglo[y + 1] = elementoActual; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment