Binary search
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.
Бинарный поиск
Массив отсортирован и содержит n элементов. Верните индекс target или -1, если он отсутствует. Держите lo и hi в пределах границ, проверяйте середину на каждом шаге и отбрасывайте ту половину, которая не может содержать целевое значение.
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.
Click Run to see the output here. · Нажмите Запустить, чтобы увидеть результат здесь.