Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active December 26, 2019 22:15
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/6ba0fc846b6baf94f8b6497726186b1a to your computer and use it in GitHub Desktop.
Save parzibyte/6ba0fc846b6baf94f8b6497726186b1a to your computer and use it in GitHub Desktop.
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