From 7ce4d109ff92cc3f04a04f8e44233fd597321fc8 Mon Sep 17 00:00:00 2001 From: bala <13452927+rfgsdhshgfh@user.noreply.gitee.com> Date: Sat, 13 Jan 2024 15:58:01 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8A=98=E5=8D=8A=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E7=9A=84=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bala <13452927+rfgsdhshgfh@user.noreply.gitee.com> --- ...6\347\232\204\347\256\227\346\263\225.cpp" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "2224020152/\347\254\254\344\271\235\345\215\225\345\205\203/\345\256\236\347\216\260\346\212\230\345\215\212\346\237\245\346\211\276\347\232\204\347\256\227\346\263\225.cpp" diff --git "a/2224020152/\347\254\254\344\271\235\345\215\225\345\205\203/\345\256\236\347\216\260\346\212\230\345\215\212\346\237\245\346\211\276\347\232\204\347\256\227\346\263\225.cpp" "b/2224020152/\347\254\254\344\271\235\345\215\225\345\205\203/\345\256\236\347\216\260\346\212\230\345\215\212\346\237\245\346\211\276\347\232\204\347\256\227\346\263\225.cpp" new file mode 100644 index 00000000..fc14cb38 --- /dev/null +++ "b/2224020152/\347\254\254\344\271\235\345\215\225\345\205\203/\345\256\236\347\216\260\346\212\230\345\215\212\346\237\245\346\211\276\347\232\204\347\256\227\346\263\225.cpp" @@ -0,0 +1,43 @@ +#include +#define MAXL 100 //定义表中最多记录个数 +typedef int KeyType; +typedef char InfoType[10]; +typedef struct +{ + KeyType key; + InfoType data; +} NodeType; +typedef NodeType SeqList[MAXL]; +int BinSearch(SeqList R,int n,KeyType k) +{ + int low=0,high=n-1,mid,count=0; + while (low<=high) + { + mid=(low+high)/2; + printf(" 第%d次比较:在[%d,%d]中比较元素R[%d]:%d\n",++count,low,high,mid,R[mid].key); + if (R[mid].key==k) + return mid; + if (R[mid].key>k) + high=mid-1; + else + low=mid+1; + } + return -1; +} +int main() +{ + SeqList R; + KeyType k=9; + int a[]={1,2,3,4,5,6,7,8,9,10},i,n=10; + for (i=0;i