Description
给一个严格递增数列,函数int binSearch(SeqList T, KeyType k)用来二分地查找k在数列中的位置。
函数接口定义:
int binSearch(SeqList T, KeyType k)
其中T是有序表,k是查找的值。
裁判测试程序样例:
#include
using namespace std;
#define MAXLEN 50
typedef int KeyType;
typedef struct
{ KeyType key;
} elementType;
typedef struct
{ elementType data[MAXLEN+1];
int len;
} SeqList;
void creat(SeqList &L)
{ int i;
cin>>L.len;
for(i=1;i<=L.len;i++)
cin>>L.data[i].key;
}
int binSearch(SeqList T, KeyType k);
int main ()
{ SeqList L; KeyType k;
creat(L);
cin>>k;
int pos=binSearch(L,k);
if(pos==0) cout<<
Output
输出这个值在表内的位置,如果没有找到,输出