#二分查找
use strict;
sub binary_search {
my ($target, @v) = @_;
my $left = 0;
my $right = @v - 1;
while ($left < $right) {
my $mid = ($left + $right) >> 1;
if ($v[$mid] >= $target) {
$right = $left;
} else {
$left = $mid + 1;
}
}
$left;
}
my $left = binary_search(8, (1, 3, 5, 8));
print $left;
标签:binary,search,right,mid,Perl,算法,数据结构,my,left
From: https://www.cnblogs.com/zhengel/p/16637779.html