#include using namespace std;
#define maxsize 50
typedef int keytype;
typedef struct
elemtype;
typedef struct
sstable;
void create(sstable &t)
////方法1,
int search_bin(sstable t, keytype k)
else if(t.r[count+min].keyk)
else
} if(flag)
else
} //
int main ()
elemtype;
typedef struct
sstable;
void create(sstable &t)
int search_bin(sstable t, keytype k);
int main ()
{ sstable t; keytype k;
create(t);
cin>>k;
int pos=search_bin(t,k);
if(pos==0) cout<<"not found"《第一行輸入乙個整數n,表示有序表的元素個數,接下來一行n個數字,依次為表內元素值。 然後輸入乙個要查詢的值。
輸出這個值在表內的位置,如果沒有找到,輸出"not found"。
51 3 5 7 9
7
4
5
1 3 5 7 9
10
not found
6 13 折半查詢 15分
語言要求使用c 然後發現用c語言的格式也可以過,嗯 o o這大概就是相容吧 折半查詢還是很套路的,大概就是定義好mid,low,high三個變數,設定乙個while迴圈,讓它們不斷縮小範圍。一開始的high設定下標應該是length 1,不過測試的時候寫的length也通過了。不過既然是位置嘛,下標...
6 13 折半查詢
給乙個嚴格遞增數列,函式int search bin sstable t,keytype k 用來二分地查詢k在數列中的位置。函式介面定義 int search bin sstable t,keytype k 其中t是有序表,k是查詢的值。裁判測試程式樣例 include using namespa...
基礎題目集 6 13 折半查詢 15分
函式介面定義 int search bin sstable t,keytype k 其中t是有序表,k是查詢的值。裁判測試程式樣例 include using namespace std define maxsize 50 typedef int keytype typedef struct ele...