new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
19
Task/Binary-search/PHP/binary-search-1.php
Normal file
19
Task/Binary-search/PHP/binary-search-1.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
function binary_search( $array, $secret, $start, $end )
|
||||
{
|
||||
do
|
||||
{
|
||||
$guess = (int)($start + ( ( $end - $start ) / 2 ));
|
||||
|
||||
if ( $array[$guess] > $secret )
|
||||
$end = $guess;
|
||||
|
||||
if ( $array[$guess] < $secret )
|
||||
$start = $guess;
|
||||
|
||||
if ( $end < $start)
|
||||
return -1;
|
||||
|
||||
} while ( $array[$guess] != $secret );
|
||||
|
||||
return $guess;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue