PHP 查找-二分查找



function binSearch($arr, $search) {     $height = count($arr) - 1;     $low    = 0;     while ($low <= $height) {         $mid = floor(($low + $height) / 2);         if ($arr[$mid] === $search) {             return $mid;         }         if ($arr[$mid] < $search) {             $low = $mid + 1;         }         if ($arr[$mid] > $search) {             $height = $mid - 1;         }     }     return '查找失败'; }

標籤:  Release    PHP    Code    algorithm    更多