Problem1785--折半查找

1785: 折半查找

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 0
[Submit] [Status] [Web Board] [Creator:]

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<<

Input

其中T是有序表,k是查找的值

Output

输出这个值在表内的位置,如果没有找到,输出

Sample Input Copy

5
1 3 5 7 9
7

Sample Output Copy

4

Source/Category

20