标签:
function binarySearch($arr,$findval,$leftIndex,$rigthIndex){ if($leftIndex > $rigthIndex){ echo ‘找不到这个数‘; return ; } $middleIndex = round(($leftIndex+$rigthIndex)/2); if($findval > $arr[$middleIndex]){ binarySearch($arr, $findval, $middleIndex+1, $rigthIndex); }else if($findval < $arr[$middleIndex]){ binarySearch($arr, $findval, $leftIndex, $middleIndex-1); }else{ echo ‘这个数的下标是‘. $middleIndex; } }
标签:
原文地址:http://www.cnblogs.com/wtb123456/p/4207356.html