二分查找
int binary_search(int a[], int len, int key){
int l = 0, h = len - 1;
int m;
while(l <= h){
m = (l + h) / 2;
if(a[m] == key)
return m;
else if(a[m] < key)
l = m + 1;
else
h = m - 1;
}
return -1; // 未找到
}
int binary_search(int a[], int len, int key){
int l = 0, h = len - 1;
int m;
while(l <= h){
m = (l + h) / 2;
if(a[m] == key)
return m;
else if(a[m] < key)
l = m + 1;
else
h = m - 1;
}
return -1; // 未找到
}