标签:blog io ar on div log cti as tt
<?php class BinSch{ /* * 二分查找,针对顺序表才有用 */ public function search($arr,$k,$low,$high){ if($low<=$high){ $mid = floor(($low+$high)/2); } if ($arr[$mid] == $k){ return $mid; } if($arr[$mid]>$k){ return $this->search($arr, $k, $low, $mid-1); } if ($arr[$mid]<$k){ return $this->search($arr, $k, $mid+1, $high); } return false; } } class Client{ public static function main(){ $arr = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); $obj = new BinSch(); echo $obj->search($arr, 10, 0, 15); } } Client::main(); ?>
标签:blog io ar on div log cti as tt
原文地址:http://www.cnblogs.com/taijun/p/4152814.html