C++ Algorithm Function find_first_of()C++ Algorithm find_first_of() function compares the values stored in two containers i.e [first1, last1) and [first2, last2). If an element similar to the one in the range [first2, last2) is found in [first1, last1) then an iterator to that element is returned by the function. In the situations where more than one similar element is present in both the ranges, the iterator to the first similar element is returned. If the case arises where no two elements are common in the range then an iterator to last1 element is returned. SyntaxParameterfirst1: 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 valueThe function returns an iterator to the first common element of the range [first1, last1) that is also a part of the range [first2,last2).In case no such element is found then the function returns last1 element. Example 1Output: Match 1 is: A Match 1 is: a Example 2Output: First vowel has been discovered at index 1 ComplexityThe complexity of the function is specified by count1*count2. Here countX specifies the distance between the firstX and lastX. The comparison is done until a matching element is found. Data racesFrom both the ranges some of the elements are accessed. ExceptionsThe function throws an exception if any of the argument throws one. Next TopicC++ Algorithm find_if Function |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India