标签:
一直不会博大精深的二分查找...(惭愧)
先贴几个参考资料学习下
[1]http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html
再贴个普通的二分
1 int binary_search(int left, int right, int value) { 2 int l = left, r = right; 3 while(l <= r) { 4 int mid = (l + r) >> 1; 5 if(arr[mid] < value) l = mid + 1; 6 else if(arr[mid] > value) r = mid - 1; 7 else return mid; 8 } 9 return -1; 10 }
标签:
原文地址:http://www.cnblogs.com/mitrenick/p/4843742.html