/**
- a 為數(shù)組逾滥,low:最小數(shù) ,high:最大數(shù) value:需要查找的值 時間復(fù)雜度 a.count,a.count/2,a.count/4,a.count/2^k (k為循環(huán)的次數(shù))似忧, a.count/2^k >=1所以 k = log2(a.count) (2為底,a.count對數(shù))
時間復(fù)雜度O(log2(a.count))
/
int BrinarySearch(int a,int low,int high,int value){
if (low > high) {
return -1;
}
int mid = (low + high)/2;
if (value == a[mid]) {
return a[mid];
}
if (a[mid] > value) {
BrinarySearch(a, low, mid -1, value);
}else {
BrinarySearch(a, mid+1, high, value);
}
return -1;
}