标签:style blog color ar sp div log bs 算法
二分查找
int binary_search(int a[],int len,int goal) { int beg = 0; int end = len - 1; while(beg <= end) { int middle = (end + beg + 1)/2; if(a[middle] == goal) return middle; if(a[middle] > goal) end = middle - 1; else beg = middle + 1; } return -1; }
标签:style blog color ar sp div log bs 算法
原文地址:http://www.cnblogs.com/kangbry/p/4052481.html