[code]SEARCH:
for ( do{$min=0; $max=$#samples; $found_target=0;}; $min<=$max; ) {
$pos = int(($max+$min)/2);
my $test_val = $sample[$pos];
if ($target == $test_val) {
$found_target = 1;
last SEARCH;
}
elsif ($target < $test_val) {
$max = $pos - 1;
}
else {
$min = $pos + 1;
}
}[/code]
阅读全文
收起全文