in reply to Re^5: Modified Binary Search
in thread Modified Binary Search
How about finding the smallest index that contains a value equal or greater than your target
sub binary_search { my ($str, $a) = @_; my $l = 0; my $h = @$a; while ($l < $h) { my $p = int (($l + $h) / 2); if ($a->[$p] lt $str) { $l = $p + 1; } else { $h = $p; } } $l }
update: minor changes to the sub.
|
|---|