关于二分查找的问题
为什么输入1,编译器就炸了#include <stdio.h>
#define NUM 10
int main()
{
int a[NUM]={1,2,3,4,5,6,7,8,9,10};
int left=0,right=NUM-1,mid,key;
mid=(left+right)/2;
printf("Enter kay:");
scanf("%d",&key);
while(left<right&&a[mid]!=key)
{
if(key<a[mid])
right=mid-1;
else if(key>a[mid])
left=mid+1;
mid=(left+right)/2;
}
if(a[mid]==key)
printf("found");
else
printf("no found");
return 0;
}
[此贴子已经被作者于2016-12-12 22:22编辑过]