C++ Algorithm Functions search_n()C++ Algorithm search_n() function searches the container [first,last) for the occurrence of a sequence of count elements, that is every element is searched to check whether it satisfies a given pred. An iterator to first element satifisying the condition is returned, else an iterator to last is returned. SyntaxParameterfirst: It is a forward iterator to the first element of the range, where the element itself is included in the range. last: It is a forward iterator to the last element of the range, where the element itself is not included in the range. count: It gives the least number of elements that are supposed to be matching a condition. val: The argument specifies the conditional value or the pred condition for which the function search_n is applied on a range. pred: It is a Binary function that accepts two arguments, and gives a boolean result. Return valueThe function returns an iterator to the first element which matches the pred, if no such element is found then an iterator to the last element is returned. Example 1Output: Two times 60 has been at position 2 Example 2Output: Value u2 has been found at position 5 ComplexityThe complexity of the function is linear starting from the first element to the last one. Data racesSome or all of the container objects are accesed. ExceptionsThe function throws an exception if any of the container elements throws one. Next TopicC++ Algorithm swap 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