用于有序序列
#include <iostream>
using namespace std;
int erfen(int a[],int r,int target)
{
int low=0,hight=r,middle;
while(low<=hight)
{
middle=(low+hight)/2;
if(a[middle]==target)
{
return middle;
}
else if(target>a[middle])
{
low=middle+1;
}
else if(target<a[middle])
{
height=middle-1;
}
}
return -1;
}
int main ()
{
int a[10]={2,3,5,8,9,10,12,13,15,23};
int index=erfen(a,9,23);
cout << index <<endl;
return 0;
}