Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 26, 2019 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/30a07f94a93bac9a0bcb5c94bb8459d7 to your computer and use it in GitHub Desktop.
Save parzibyte/30a07f94a93bac9a0bcb5c94bb8459d7 to your computer and use it in GitHub Desktop.
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