php二分法查找
作者:互联网
//二分查找(数组里查找某个元素) function bin_sch($array, $low, $high, $k) { if ($low <= $high) { $mid = intval(($low + $high) / 2); if ($array[$mid] == $k) { return $mid; } elseif ($k < $array[$mid]) { return bin_sch($array, $low, $mid - 1, $k); } else { return bin_sch($array, $mid + 1, $high, $k); } } return -1; }
标签:function,bin,sch,二分法,查找,low,php 来源: https://www.cnblogs.com/huay/p/10367467.html