1 #include <iostream> 2 #include <algorithm> 3 4 using namespace std; 5 int a[100]; 6 int binarysearch(int a[],int size,int att){ 7 sort(a,a+size);//一定要有序!!!!! 8 int L=0; 9 int R=size-1; 10 while(L<R) { 11 int mid = L + (R - L) / 2; 12 13 if (att == a[mid]) 14 return mid; 15 else if(att>a[mid]){ 16 L=mid+1; 17 18 } else 19 L=mid-1; 20 21 } 22 } 23 int main(){ 24 25 }