C++ Algorithm Function search()C++ Algorithm search() function searches the range [first1, last1) for the occurrence of a subsequence defined by the range [first2, last2), and an iterator to the first element is returned. If the subsequence does not exist then an iterator to the last1 is returned. SyntaxParameterfirst1: It is a forward iterator to the first element of the [first1, last1). last1: It is a forward iterator to the last element of the [first1, last1). first2: It is a forward iterator to the first element of the [first2, last2). pred: It is a binary function that accepts two elements as arguments and performs the task designed by the function. Return valueThe function returns an iterator to the first element of the first occurrence of the subsequence, else returns the last1 element. Example 1Output: patt1 found at position 1 patt2 not found Example 2Output: Vector2 is present at index:2 ComplexityThe function has linear complexity from the first1 element to the last1 element. Data racesObjects in both ranges are accessed. ExceptionsThe function throws an exception if any of the argument throws one.
Next TopicC++ Algorithm is_permutation Function
|