本帖最后由 唐学松 于 2012-9-23 11:58 编辑
class zheban
{
public static void main(String args[])
{
int [] arr={2,6,8,10,12,18,};
int index=array(arr,10);
System.out.println("index"+index);
}
public static int array(int[] arr,int key)
{
int min=0;
int max=0;
int mid=0;
max=arr.length-1;
mid=(max+min)/2;
while (arr[mid]!=key)
{
if (key>arr[mid])
{min=mid+1;}
else if (key<arr[mid])
{min=mid-1 ;}
}
return mid;
}
}
|