Created
August 7, 2019 16:36
-
-
Save parzibyte/c7a610d54d3c78f237223dcab1edf050 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
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