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.
การค้นหาแบบทวิภาค
อาเรย์นั้น sorted และมี n องค์ประกอบ คืนค่า index ของ target หรือ -1 หากไม่พบ Keep lo และ hi Within bounds, ตรวจสอบค่าตรงกลางในแต่ละขั้นตอน และตัดครึ่งที่ไม่สามารถมีเป้าหมายได้
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) для sorted array ความยาว n: กลับ index ของ target หรือ -1 หากไม่พบ
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่