Binary search · Recherche binaire
Binary search
The array is sorted and has n elements. Return the index of target, or -1 if it isn't present. Keep lo and hi bounds, check the middle each step, and discard the half that can't contain the target.
Recherche binaire
Le tableau est trié et contient n éléments. Retournez l'indice de target, ou -1 s'il n'est pas présent. Gardez lo et hi bornes, vérifiez le milieu à chaque étape, et éliminez la moitié qui ne peut pas contenir la cible.
Complete int binary_search(const int *a, int n, int target) for a sorted array of length n: return the index of target, or -1 if absent. · Complétez int binary_search(const int *a, int n, int target) pour un tableau trié de longueur n : retournez l'index de target, ou -1 s'il est absent.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.