C ++ STL's non-mutating algorithms is a set of template functions that do not destroy operation data, it is used for processing sequence data one by one, element search, subsequence search, statistics, and matching.
The adjacent_find algorithm is used to find adjacent element pairs that meet equal or equal conditions. There are two types of function prototypes: one is to find the iterator position of the first element in the element pair when two consecutive elements are equal in the iterator range [first, last. The other is to use binary predicates to determine binary_pred, and find the adjacent element pairs that meet the binary_pred condition on the iterator range [first, last). If not found, return last.
Function prototype:
template<class ForwardIterator> ForwardIterator adjacent_find( ForwardIterator _First, ForwardIterator _Last );template<class ForwardIterator , class BinaryPredicate> ForwardIterator adjacent_find( ForwardIterator _First, ForwardIterator _Last, BinaryPredicate _Comp );
Sample Code:
/*************************************** * **************************** Copyright (c) jerry Jiang * file name: adjacent_find.cpp * Author: Jerry Jiang * Create Time: 2011-9-30 22:07:22 * mail: jbiaojerry@gmail.com * blog: http://blog.csdn.net/jerryjbiao * description: A simple program interprets the four non-Variable Algorithms in the C ++ STL algorithm series: find the container element adjacent_find *********************************** * *****************************/# includ E <algorithm> # include <list> # include <iostream> using namespace STD; // checks whether X and Y are parity bool parity_equal (int x, int y) {return (x-y) % 2 = 0? 1: 0;} int main () {// initialize the list of linked lists <int> ilist; ilist. push_back (3); ilist. push_back (6); ilist. push_back (9); ilist. push_back (11); ilist. push_back (11); ilist. push_back (18); ilist. push_back (20); ilist. push_back (20); // output list <int>: iterator ITER; For (iter = ilist. begin (); iter! = Ilist. end (); ++ ITER) {cout <* ITER <";}cout <Endl; // query the list of elements with the same adjacent areas <int> :: iterator iresult = adjacent_find (ilist. begin (), ilist. end (); If (iresult! = Ilist. end () {cout <"the first pair of equal Adjacent Elements in the linked list is:" <Endl; cout <* iresult ++ <Endl; cout <* iresult <Endl;} // find the adjacent element iresult = adjacent_find (ilist. begin (), ilist. end (), parity_equal); If (iresult! = Ilist. end () {cout <"the first pair of elements with the same parity in the linked list is:" <Endl; cout <* iresult ++ <Endl; cout <* iresult <Endl;} return 0 ;}
**************************************** **************************************** **************************************** *******
C ++ classic bibliography index and resource download:Http://blog.csdn.net/jerryjbiao/article/details/7358796
**************************************** **************************************** **************************************** ********