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;
}
posted @ 2011-11-28 10:26  meieiem  阅读(224)  评论(0编辑  收藏  举报