码迷,mamicode.com
首页 > 其他好文 > 详细

二分查找

时间:2016-02-25 15:42:30      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

FROM:

http://blog.csdn.net/int64ago/article/details/7425727

对于YES_LEFT或者NO_RIGHT

int bSearch(int begin, int end, int e)  
{  
    int mid, left = begin, right = end;  
    while(left <= right)  
    {  
        mid = (left + right) >> 1;  
        if(num[mid] >= e) right = mid - 1;  
        else left = mid + 1;  
    }  
    return left;  
}  

对于YES_RIGHT或者NO_LEFT

int bSearch(int begin, int end, int e)  
{  
    int mid, left = begin, right = end;  
    while(left <= right)  
    {  
        mid = (left + right) >> 1;  
        if(num[mid] > e) right = mid - 1;  
        else left = mid + 1;  
    }  
    return right;  
}  

 

二分查找

标签:

原文地址:http://www.cnblogs.com/tun117/p/5217005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!