求字符串2是是否是字符串1的字串

template<typename T>
T my_search(T first1, T last1, T first2, T last2)
{
    int d1 = distance(first1, last1);
    int d2 = distance(first2, last2);
    if(d1 < d2)
    return last1;
    
    T current1 = first1;
    T current2 = first2;
    while(current2 != last2)
    {
        if(*current1 = *current2)
        {
            ++current1;
            ++current2;
        }
        else
        {
            if(d1 == d2)
            {
                return last1;
            }
            else
            {
                current1 = ++first1;
                current2 = first2;
                --d1;
            }
        }
    }
    return first1;
}

 

posted on 2014-05-04 11:00  yi_meng  阅读(469)  评论(0编辑  收藏  举报

导航