Javatpoint Logo
Javatpoint Logo

C++ Algorithm Function adjacent_find()

C++ Algorithm adjacent_find() function performs a search operation on the range [first, last] for the very first occurrence of two consecutive matching elements. If such elements are found then an iterator to the first element of the two is returned. Otherwise, the last element is returned.

Syntax

Parameter

first: It is a forward iterator to the first element in the range.

last: It is a forward iterator to the last element 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 range[first,last) if two consecutive matching elements are found else the last element is returned.

Example 1

Output:

In the given range the first pair of sequence that is repeated are: 50
In the given range the second pair of sequence that is repeated are: 60

Example 2

Output:

17

Complexity

The complexity of the function is linear up to a distance between the first and last element.

Data races

Some or all of the elements of the range are accessed.

Exceptions

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






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA