#include<stdio.h>typedef struct {int key;}Tree;int Quick_Partition(Tree R[],int i,int j);void Quick_Sort(Tree R[],int s,int t);int BinarySearch(Tree SL[],int key,int n);int main(void){int i,n,key;Tree R[50];printf("请输入您想输入的数据序列元素的个数:");scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&R[i].key); //Quick_Partition( R, 0, n-1); Quick_Sort( R, 0, n-1); for(i=0;i<n;i++) printf("%d",R[i].key); printf("请输入要查找的关键字:");scanf("%d",&key); BinarySearch( R, key, n);}
int Quick_Partition(Tree R[],int i,int j){R[0]=R[i];while(i<j){while(i<j&&R[j].key>=R[0].key)j--;if(i<j){R[i]=R[j];i++;}while(i<j&&R[i].key<=R[0].key)i++;if(i<j){R[j]=R[i];j--;}R[i]=R[0];return i;}}void Quick_Sort(Tree R[],int s,int t){int i;while(s<t){i=Quick_Partition(R,s,t);Quick_Sort(R,s,i-1);Quick_Sort(R,i+1,t);}//for(j=0;j<k;j++) //printf("%d\n",R[j].key);}int BinarySearch(Tree SL[],int key,int n){int low=1;int high=n;int mid;while(low<=high){mid=(low+high)/2;if(key==SL[mid].key){return mid;}else if(key>SL[mid].key)low=mid+1;else high=mid-1;}return 0;}
int Quick_Partition(Tree R[],int i,int j){R[0]=R[i];while(i<j){while(i<j&&R[j].key>=R[0].key)j--;if(i<j){R[i]=R[j];i++;}while(i<j&&R[i].key<=R[0].key)i++;if(i<j){R[j]=R[i];j--;}R[i]=R[0];return i;}}void Quick_Sort(Tree R[],int s,int t){int i;while(s<t){i=Quick_Partition(R,s,t);Quick_Sort(R,s,i-1);Quick_Sort(R,i+1,t);}//for(j=0;j<k;j++) //printf("%d\n",R[j].key);}int BinarySearch(Tree SL[],int key,int n){int low=1;int high=n;int mid;while(low<=high){mid=(low+high)/2;if(key==SL[mid].key){return mid;}else if(key>SL[mid].key)low=mid+1;else high=mid-1;}return 0;}
