二分查找 模板(升序数组)

mac2022-06-30  25

1 int binSearch(const int arr[],int low,int high,int key) 2 { 3 if(low>high) 4 return -1; 5 int mid=low+(high-low)/2; 6 if(arr[mid] == key) 7 return mid; 8 return (arr[mid] > key ? binSearch(arr,low,mid-1,key) : binSearch(arr,mid+1,high,key)); 9 }

 

转载于:https://www.cnblogs.com/Pos-Proteus/p/4792391.html

相关资源:C例子:二分查找法
最新回复(0)