编辑代码

#include<stdio.h>
//调用函数
 //采用折半查找算法进行
bool Binary_Search(int a[],int length ,int elemt){
	int start = 0;
	int end = length -1;
	int mid;
	while(start<=end){
		mid  = (start+end)/2;
		if(a[mid] == elemt) {
			return true;	
		}
		else if(a[mid]>elemt) {
			start  = mid +1;
		}else{
			end = mid -1;
		}
		
	}
	 return false; 

} 

//主函数 
int main()
{	
	int a [] = {85, 63, 52, 34, 25, 17, 6};
	int length = sizeof(a)/sizeof(a[0]);
	int search_elemt = 6; 
	bool flat =  Binary_Search(a,length,search_elemt);
	if(flat) printf("查找成功元素为\t%d\n",search_elemt);
	else printf("不存在元素 %d\n",search_elemt);
	
	return 0;
	
 }