Last active
December 26, 2019 22:15
-
-
Save parzibyte/6ba0fc846b6baf94f8b6497726186b1a 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 int particion(int arreglo[], int izquierda, int derecha) { | |
int pivote = arreglo[izquierda]; | |
// Ciclo infinito | |
while (true) { | |
while (arreglo[izquierda] < pivote) { | |
izquierda++; | |
} | |
while (arreglo[derecha] > pivote) { | |
derecha--; | |
} | |
if (izquierda >= derecha) { | |
return derecha; | |
} else {//Nota: yo sé que el else no hace falta por el return de arriba, pero así el algoritmo es más claro | |
int temporal = arreglo[izquierda]; | |
arreglo[izquierda] = arreglo[derecha]; | |
arreglo[derecha] = temporal; | |
izquierda++; | |
derecha--; | |
} | |
// El while se repite hasta que izquierda >= derecha | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment