什么是alpha-beta剪枝算法
发布网友
发布时间:2024-09-10 07:01
我来回答
共1个回答
热心网友
时间:2024-11-29 09:38
貌似是折半查找法
public class LianXi5 {
public static void main(String[] args)
{
int start,end,middle,n=12;
int []a={-2,1,5,4,8,12,17,45,56,90,100};
start = 0;
end = a.length-1;
middle = (start + end)/2;
int count=0;
while(n!=a[middle])
{
if(n>a[middle])
{
start = middle;
}
else if(n<a[middle])
{
end = middle;
}
middle=(start + end)/2;
count++;
if(count>a.length/2)
break;
}
if(count>a.length/2)
System.out .println (":"+n+"不在数组中");
else
System.out .println (":"+n+"是数组中的第"+middle+"个元素");
}
}