二分排序

来源:互联网 发布:liunx7 源码安装php 编辑:程序博客网 时间:2024/06/06 11:44

二分查找算法:
1) 递归方法实现:
int BSearch(elemtype a[],elemtype x,int low,int high)
/*在下届为low,上界为high的数组a中折半查找数据元素x*/
{
int mid;
if(low>high) return -1;
mid=(low+high)/2;
if(x==a[mid]) return mid;
if(x <a[mid]) return(BSearch(a,x,low,mid-1));
else return(BSearch(a,x,mid+1,high));
}

原创粉丝点击