Алгоритм search_end. C++

Мне необходимо реализовать алгоритм search_end по вот такому примеру: введите сюда описание изображения

Вот, что я имею:

template <class BinaryPredicate,
          class BidirectionalIterator1,
          class BidirectionalIterator2>
BidirectionalIterator1 search_end(BidirectionalIterator1 first1, 
                                  BidirectionalIterator1 last1, 
                                  BidirectionalIterator2 first2, 
                                  BidirectionalIterator2 last2,
                                  BinaryPredicate pred, 
                                  bidirectional_iterator_tag, 
                                  bidirectional_iterator_tag)
{   
    if (first2 == last2)
        return last1; 

    BidirectionalIterator1 l1 = last1;
    BidirectionalIterator2 l2 = last2;
    --l2;

    while (true)
    {   
        while (true)
        {
            if (first1 == l1)
                return last1;
            if (pred(*--l1, *l2))
                break;
        }
       
        BidirectionalIterator1 m1 = l1;
        BidirectionalIterator2 m2 = l2;

        while (true)
        {
            if (m2 == first2)
                return m1;
            if (m1 == first1)
                return last1;
            if (!pred(*--m1, *--m2))
            {
                break;
            }  
        }
    }

Но что надо сделать дальше?. Вот, что я пытался сделать:

int main()
{      
    int array[] = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 };
    int begin = 0, end = 11;        
    int* ret = 0;
    int a[3] = { 1, 2, 3 };
    search_end(array, array + 12, a, a + 3, Odd());
    Odd f;
       
    if (*ret == array[12])
    {
        std::cout << "Did not find any subsequence matching { 1, 2, 3 }" << std::endl;
    }
    else
    {
        std::cout << "The last matching subsequence is at: " << *ret << std::endl;
    }

    int b[] = { 5, 2, 3 };
    search_end(array, array + end, b, b + 2);
    if (*b == array[end])
    {
        std::cout << "Did not find any subsequence matching { 3, 2, 3 }" << std::endl;
    }
    else
    {
        std::cout << "The last matching subsequence is at: " << *b << std::endl;
    }    
}

Ответы (0 шт):