Syntax:
#include <algorithm> forward_iterator adjacent_find( forward_iterator start, forward_iterator end ); forward_iterator adjacent_find( forward_iterator start, forward_iterator end, BinPred pr );
The adjacent_find() function searches between start and end for two consecutive identical elements. If the binary predicate pr is specified, then it is used to test whether two elements are the same or not. The return value is an iterator that points to the first of the two elements that are found. If no matching elements are found, the returned iterator points to end. For example, the following code creates a vector containing the integers between 0 and 10 with 7 appearing twice in a row. adjacent_find() is then used to find the location of the pair of 7's:
嗯,这个算法的主要意思就是:在一个数组中寻找两个相邻的元素。如果相等呢,就返回这两个相等元素第一个元素的迭代器,呵呵,不等的话,就返回v.end().
执行结果:
Find adjancent elements is 88