Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 16:41
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/17600756e77caf986d388116960cb24d to your computer and use it in GitHub Desktop.
Save parzibyte/17600756e77caf986d388116960cb24d to your computer and use it in GitHub Desktop.
// Arreglo para probar
String[] arreglo = { "Chris", "Claire", "Django", "John", "Leon", "Morty", "Rick", "Saul", "Tuco", "Walter" };
String busqueda = "Morty";
// Probar primero con la recursiva
int indiceDelElementoBuscado = busquedaBinariaRecursiva(arreglo, busqueda, 0, arreglo.length - 1);
System.out.println("[Recursivo] -- El elemento buscado ("
+ busqueda
+ ") se encuentra en el index "
+ indiceDelElementoBuscado);
// Ahora con la que usa el ciclo while
indiceDelElementoBuscado = busquedaBinariaConWhile(arreglo, busqueda);
System.out.println("[Con ciclo While] -- El elemento buscado ("
+ busqueda
+ ") se encuentra en el index "
+ indiceDelElementoBuscado);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment