写出二分查找算法的两种实现

2023-07-06   


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 else return(BSearch(a,x,mid+1,high));
  
   2)非递归方法实现:
   int BSearch(elemtype a[],keytype key,int n)
  
   int low,high,mid;
   low=0;high=n-1;
   while(low


相关内容:

  1. ASP.NET笔试题小汇总
  2. 西部世纪面试题
  3. 西部世纪.net笔试题面试题
  4. Python的两道面试题
  5. .NET remoting的两种通道是什么
  6. .NET remoting中对象激活的两种方式