Binary search · البحث الثنائي
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · تحتاج هذه الصفحة إلى متصفح حديث (يدعم SharedArrayBuffer). يرجى تحديث Chrome أو Edge أو Firefox أو Safari إلى أحدث إصدار.
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.
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. · أكمل int binary_search(const int *a, int n, int target) لمصفوفة مرتبة بطول n: أدرج الفهرس الخاص بـ target، أو -1 إن لم يكن موجودًا.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.