- public static int halfSearch2(List<String> list,String key,Comparator<String> cmp)
- {
- int max,min,mid;
- max = list.size()-1;
- min = 0;
- while(min<=max)
- {
- mid = (max+min)>>1;// /2;
- String str = list.get(mid);
- int num = cmp.compare(str,key);
- if(num>0)
- max = mid -1;
- else if(num<0)
- min = mid + 1;
- else
- return mid;
- }
- return -min-1;
复制代码 代码段如上,这个插入点为什么是min呢,不理解,求解答 |