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Ԫص±ǣ"<