perl 二分法查找.docVIP

  • 3
  • 0
  • 约2.71千字
  • 约 6页
  • 2018-01-18 发布于河南
  • 举报
perl 二分法查找

#!/usr/bin/perl-w @array=(a,f,b,c,d,ab,e,7,8,23,9); @list=sort(@array); print please input the content you want to look for \n; print if the content exists ,you will get the position\n; chomp ($k=STDIN); $min=0; $max=$#list; if($k lt $list[$min] or $k gt $list[$max]) { printNOT EXIST!\n; } else{ while($k ge $list[$min] and $k le $list[$max]) { if($k eq $list[$min]) { print the content is in NO. ; print $min+1; print \n; last; } elsif($k eq $list[$max]) { print the content is in NO. ; print $max+1; print \n; last; } else { $i=($min+$max)/2;

文档评论(0)

1亿VIP精品文档

相关文档