标签:
int binary_search(const int arr[], int start, int end, int key) { int mid; while (start <= end) { mid = start + (end - start) / 2; //直接平均可能溢位,所以用此算法 if (arr[mid] < key) start = mid + 1; else if (arr[mid] > key) end = mid - 1; else return mid; } return -1; }
标签:
原文地址:http://www.cnblogs.com/wqkant/p/5328991.html