Skip to content

Instantly share code, notes, and snippets.

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