From f6071505707082ec9116a6ba964690d82f254cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8A=E5=8F=B6?= <3184463755@qq.com> Date: Sat, 28 Oct 2023 17:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=98=E5=8D=8A=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.折半查找.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 1.折半查找.cpp diff --git a/1.折半查找.cpp b/1.折半查找.cpp new file mode 100644 index 0000000..3af25a7 --- /dev/null +++ b/1.折半查找.cpp @@ -0,0 +1,65 @@ +#include +using namespace std; + +#define OK 1 +#define ERROR 0 +#define MAXSIZE 100 + +typedef int KeyType; +typedef struct +{ + int elem[MAXSIZE]; + int length; +}SSTable; //һ˳Ԫ + +int Search_Bin(SSTable ST,KeyType key) +{ + int low,high,mid; + low=1; + high=ST.length; + while(low<=high) + { + mid=(low+high)/2; //۰룬ȽϵԪ + cout<<" "<key) //ؼִڲҵ֣Сƶ + high=mid-1; + else if(ST.elem[mid]>ST.length; + cout<<"Ԫ"<>ST.elem[i]; + } + cout<<"ҪҵԪأ"<>n; + cout<<"ȽϵԪУ"; + a=Search_Bin(ST,n); + if(a>=0) + cout<<"\nԪص±ǣ"<