java 二分搜索

private int binarySearch(List<ShowData>ls,int des)
{
int min=0;
int max=ls.size()-1;
int mid=(max+min)/2;

while(min<=max)
{
mid=(max+min)/2;
ShowData data=ls.get(mid);
if(des>data.addTotalMin&&des<=data.addTotalMax)
{
return mid;
}else
{
if(des<data.addTotalMin)
{
max=mid-1;
}else
{
min=mid+1;
}
}
}
return mid;
}

你可能感兴趣的:(java)