publicint binarySearch(int[] dataset,int data,int beginIndex,int endIndex)
{
int midIndex = (beginIndex+endIndex)/2;
if(data <dataset[beginIndex] ¦ ¦data>dataset[endIndex] ¦ ¦beginIndex>endIndex)return -1;
if(data <dataset[midIndex])
{
return binarySearch(dataset,data,beginIndex,midIndex-1);
}elseif(data>dataset[midIndex])
{
return binarySearch(dataset,data,midIndex+1,endIndex);
}else
{
return midIndex;
}
}
|