标题:折半法查数,,两个错误,,大家帮我看看哪里错了
取消只看楼主
showtime110
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-2-18
 问题点数:0 回复次数:0 
折半法查数,,两个错误,,大家帮我看看哪里错了

int binsearch(int x,int v[],int n) { int low,high,mid; low=0; high=n-1; mid=(low+high)/2; while(low<=high) { if(x<v[mid]) high=mid-1; else if(x>v[mid]) low=mid+1; else return mid; } return -1;

main() { int y, a[10]={1,2,3,4,5,6,7,8,9,10}; y=binsearch(10,a,10); printf("%d",y); }

搜索更多相关主题的帖子: int low high mid else 
2005-02-25 18:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-12572-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.481577 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved