Created
December 26, 2019 06:18
-
-
Save parzibyte/0e5baa8d5aad8d523f08e731d01ec314 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(int[] 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++) { | |
int elementoActual = arreglo[y], | |
elementoSiguiente = arreglo[y + 1]; | |
if (elementoActual > elementoSiguiente) { | |
// 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