[转]算法课上老师给的标准,用来参考,其实最重要的是态度[
1 int binarySearch(int *arr, int left, int right, int val) { 2 int mid = 0; 3 if (left > right) 4 return -1; 5 else 6 mid = (left + right) / 2; 7 8 if (val == arr[mid]) 9 return mid; 10 else if (val < arr[mid]) 11 return binarySearch(arr, left, (mid - 1), val); 12 else 13 return binarySearch(arr, (mid + 1), right, val); 14 }
^_^