c语言数据结构---二分查找

#include
#include
int main(){
	int a[1000];
	printf("input the length:");
	int length;
	scanf("%d",&length);
	printf("input some data:\n");
	for(int i=1;i<=length;i++){
		scanf("%d",&a[i]);
	} 
	for(int i=1;ia[j]){
				int t=a[i];
				a[i]=a[j];
				a[j]=t;
			}
		}
	 } 
	int low=0;
	int high=length;
	int mid=(low+high)/2;
	printf("input what num would you find?\n");
	int temp;
	scanf("%d",&temp);
	while(low<=high){
		if(tempmid){
			low=mid+1;
		}
		else if(temp==mid){
			printf("success find!\n");
			break;
		}
		mid=(low+high)/2;
	} 
	if(low>high)printf("can't find the num\n");
}

你可能感兴趣的:(数据结构,c语言,算法)