首页 > Other > php函数 二分法 快速查找int

php函数 二分法 快速查找int

$array = array(1,2,3,4,11,12,124,1245);
function found($array,$low,$hight,$k)
{
$index = intval(($low+$hight) / 2);
if($k == $array[$index])
{
return $index;
}elseif($k < $array[$index])
{
return found($array,$low,$index-1,$k);
}else{
return found($array,$index+1,$hight,$k);
}
}
echo found($array,0,$count,1245);

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: