adjacent_find
Searches for two adjacent elements that are equal (by some criterion)
You're viewing an older version of this page (#4118). View the current version.
Definition
The adjacent_find() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class ForwardIterator >
ForwardIterator adjacent_find(
ForwardIterator first,
ForwardIterator last
);
template < class ForwardIterator , class BinaryPredicate >
ForwardIterator adjacent_find(
ForwardIterator first,
ForwardIterator last,
BinaryPredicate comp
);Parameters:
| Parameter | Description |
| first | A forward iterator addressing the position of the first element in the range to be searched |
| last | A forward iterator addressing the position one past the final element in the range to be searched |
| comp | The binary predicate giving the condition to be satisfied by the values of the adjacent elements in the range being searched |
Description
The adjacent_find algorithm searches for two adjacent elements that are either equal or satisfy a specified condition.
Return Value
The first version of adjacent_find returns the first iterator i such that i and i+1 are both valid iterators in [first, last), and such that *i == *(i+1). It returns last if no such iterator exists.
The second version of adjacent_find returns the first iterator i such that i and i+1 are both valid iterators in [first, last) and such that binary_pred (*i, *(i+1)) is true. It returns last if no such iterator exists.
Complexity
The complexity is linear. If first == last then no comparison are performed; otherwise, at most (last - first) - 1 comparisons.
References
See also
- http://www.codecogs.com/reference/computing/algorithms/nonmodifying/find.php"find"
- http://www.codecogs.com/reference/computing/stl/algorithms/nonmodifying/mismatch.php"mismatch"
- http://www.codecogs.com/reference/computing/stl/algorithms/nonmodifying/equal.php"equal"
- http://www.codecogs.com/reference/computing/stl/algorithm/nonmodifying/search.php"search"