Binary search · Pencarian biner
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.
Pencarian biner
Array tersebut terurut dan memiliki n elemen. Kembalikan indeks dari target, atau -1 jika tidak ada. Jaga lo dan hi batas, periksa tengah setiap langkah, dan buang separuh yang tidak bisa menampung target.
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. · Selesaikan ⟨int binary_search(const int *a, int n, int target)⟩ untuk senarai tersusun sepanjang ⟨n⟩: kembalikan indeks bagi ⟨target⟩, atau ⟨-1⟩ jika tiada.
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.