Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 16:36
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/c7a610d54d3c78f237223dcab1edf050 to your computer and use it in GitHub Desktop.
Save parzibyte/c7a610d54d3c78f237223dcab1edf050 to your computer and use it in GitHub Desktop.
func busquedaBinariaRecursiva(arreglo []int, busqueda, izquierda, derecha int) (indice int) {
if izquierda > derecha {
return -1
}
indiceDelMedio := int(math.Floor((float64(izquierda+derecha) / 2)))
elementoDelMedio := arreglo[indiceDelMedio]
if elementoDelMedio == busqueda {
return indiceDelMedio
}
if busqueda < elementoDelMedio {
derecha = indiceDelMedio - 1
} else {
izquierda = indiceDelMedio + 1
}
return busquedaBinariaRecursiva(arreglo, busqueda, izquierda, derecha)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment