LYXin's Blog

Here I stand. And here I'll stay.

lower_bound

template <class ForwardIterator, class T>
ForwardIterator lower_bound (ForwardIterator first, ForwardIterator last, const T& val)
{
    ForwardIterator it;
    iterator_traits<ForwardIterator>::difference_type count, step;
    count = distance(first, last);
    while(count > 0)
    {
        it = first; step=count / 2; advance(it, step);
        if( *it < val)
        {
            first = ++it;
            count -= step+1;
        }
        else count = step;
    }
    return first;
}

来自http://www.cplusplus.com/reference/algorithm/lower_bound/
感觉二分的时候可以仿照这个。。。就复制下来了

阅读更多
个人分类: templates
上一篇July list
下一篇hdu2222
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭