C++ Algorithm Function find_end ()

C++ Algorithm find_end()function searches for the last occurrence of a pattern in the container, or say the last occurrence of a small portion of the sequence in the container. It basically searches the range specified by [first1,last1)for the occurrence of sequence which is defined by [first2,last2). If the occurrence is found, an iterator to the first element is returned, otherwise the last1 is returned.

Syntax

Parameter

first1: It is a forward iterator to the first element in the range [first1, last1) where the element itself is included in the range.

last1: It is a forward iterator to the last element in the range [first1, last1) where the element itself is not included in the range.

first2: It is a forward iterator to the first element in the range [first2, last2) where the element itself is included in the range.

last2: It is a forward iterator to the last element in the range [first2, last2) where the element itself is not included in the range.

pred: It is a binary function that accepts two elements as arguments and performs the task designed by the function.

Return value

The function returns an iterator to the first element of the last occurrence of [first2,last2)in the range [first1,last1).In case the sequence is not found then the function returns last1 value.

Example 1

Output:

patt1 is last found at the position 5
patt2 is last found at the position 3

Example 2

Output:

11

Complexity

The complexity of the function is specified by count2*(1+count1-count2. Here countX specifies the distance between the firstX and lastX.

Data races

Objects in both ranges are accessed.

Exceptions

The function throws an exception if any of the argument throws one.






Latest Courses