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. · השלם את int binary_search(const int *a, int n, int target) למערך מסודר באורך n: החזר את האינדקס של target, או -1 אם אינו קיים.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.