Created
September 17, 2019 04:29
-
-
Save Jason-cqtan/b62586f62464cef522147c5e904132b6 to your computer and use it in GitHub Desktop.
php二分查找
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bin_sch($array, $low, $high, $k){ | |
if ($low <= $high){ | |
$mid = intval(($low+$high)/2); | |
if ($array[$mid] == $k){ | |
return $mid; | |
}elseif ($k < $array[$mid]){ | |
return bin_sch($array, $low, $mid-1, $k); | |
}else{ | |
return bin_sch($array, $mid+1, $high, $k); | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment