template <class ForwardIterator> ForwardIterator adjacent_find( ForwardIterator qFirst, ForwardIterator qLast );
#include <algorithm>
template <class ForwardIterator,class BinaryPredicate> ForwardIterator adjacent_find( ForwardIterator qFirst, ForwardIterator qLast BinaryPredicate qComp );
#include <iostream> #include <vector> #include <algorithm> // Comparison function bool OneMoreThan(int iInt1, int iInt2) { return ((iInt1 + 1) == iInt2); } int main() { using namespace std; vector<int> qV; // Put entries into the vector [4, 2, 3, 3, 5] qV.push_back(4); qV.push_back(2); qV.push_back(3); qV.push_back(3); qV.push_back(5); // Check for equal adjacent entries vector<int>::iterator qFound = adjacent_find(qV.begin(), qV.end()); cout << "First Search:" << endl; if (qFound == qV.end()) { cout << "Not Found" << endl; } else { cout << "Found with value = " << (*qFound) << endl; } // Check for OneMoreThan() adjacent entries qFound = adjacent_find(qV.begin(), qV.end(), OneMoreThan); cout << "Second Search with Comparison:" << endl; if (qFound == qV.end()) { cout << "Not Found" << endl; } else { cout << "Found with value = " << (*qFound) << endl; } cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.