标签:oal == else binary logs arch blog bin span
int binary_search(int* a, int len, int goal) { int low = 0;int high = len -1; while (low <= high) { int middle = (high - low) / 2 + low; // 直接使用(high + low) / 2 可能导致溢出 if (a[middle] == goal) return middle; //表示找到了 //在左半边 else if (a[middle] > goal) high = middle - 1; //在右半边 else low = middle + 1; } //没找到 return -1; }
标签:oal == else binary logs arch blog bin span
原文地址:http://www.cnblogs.com/fzuhyj/p/7623379.html