类别:算法 | 组件类型:函数 |
template <class ForwardIterator> ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last); template <class ForwardIterator, class BinaryPredicate> ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred);
第二个版本的adjacent_find返回第一个迭代器i使得i和i+1都是中的有效迭代器[first, last),并且使得binary_pred(*i, *(i+1))是true。如果不存在这样的迭代器,则返回last。
int A[] = {1, 2, 3, 4, 6, 5, 7, 8}; const int N = sizeof(A) / sizeof(int); const int* p = adjacent_find(A, A + N, greater<int>()); cout << "Element " << p - A << " is out of order: " << *p << " > " << *(p + 1) << "." << endl;