求大佬帮忙看看这个二分查找法哪错了,总是找不出来?
程序代码:
#include <stdio.h> #include <string.h> int main() { int a[10]={8,9,6,4,7,5,3,2,1,5},i,low,high,mid,count=0,n; scanf("%d",&n); low=0; high=10-1; while(low<=high) { mid=(high+low)/2; if(n<a[mid]) high=mid-1; else if(n>a[mid]) low=mid+1; else if(a[mid]==n) { printf("success!a[%d]=%d\n",mid,n); count++; break; } } if(count==0) printf("shibai"); return 0; }