首页 > 代码库 > 20140717 二分查找

20140717 二分查找

1、二分查找代码

二分查找的代码.  int bfind(int* a,int len,int val) {      int m = len/2;     int l = 0;     int r = len;      while(l!=m && r!= m)     {          if(a[m] > val)         {              r = m;              m = (m+l)/2;         }          else if(a[m] < val)         {              l = m;              m = (m+r)/2;         }         else              return m;     }      return -1;   //没有找到}