function array_search($a,$v)
{
$b = 0;
$n = count($a) -1;
while($b <= $n)
{
$s = floor(($b + $n)/2);
if($v == $a[$s]) return $s;
if($v > $a[$s])
{
$b = $s + 1;
continue;
}
else
{
$n = $s - 1;
continue;
}
return -1;
}
}
用二分查找法实现array_search
最新推荐文章于 2018-12-11 21:43:46 发布