Search_n () is used to find contiguous n-matched values or add predicates
Search_n (b, E, C, v)
Search_n (b, E, C, V, p)
Note: The second form of the method should be search_n_if (b, E, C, p)
#include <iostream> #include <algorithm> #include <deque>//#include <functional>//using namespace Std;int main () {deque<int> ideq;for (int i = 1; I <= 9; i++) {if (i = = 3) {ideq.push_back (i); Ideq.push_bac K (i); Ideq.push_back (i); Ideq.push_back (i); Else{ideq.push_back (i);}} for (Deque<int>::iterator iter = Ideq.begin (); ITER! = Ideq.end (); iter++) cout << *iter << endl;/*if (PO s! = string::npos) cout << "found it! "<< Pos << endl;elsecout <<" not found! "<< endl;*/deque<int>::iterator Pos;pos = Search_n (Ideq.begin (), Ideq.end (), 4, 3); if (pos! = Ideq.end ()) {Co UT << "found 4 consecutive 3! , ordinal position "<< distance (Ideq.begin (), POS) + 1 << Endl;} Else{cout << "not found! "<< Endl;} The predicate here is two dollars for pos = Search_n (Ideq.begin (), Ideq.end (), 3, 6, greater<int> ());//pos = Search_n_if (Ideq.begin (), Ideq . End (), 3, bind2nd (Greater<int> (), 6)), if (pos! = Ideq.end ()) {cout << "found 3 consecutive numbers greater than 6! Start with "<< DistanCE (Ideq.begin (), POS) + 1 << Endl;} Elsecout << "not found! "<< Endl;//system (" pause "); return 0;}
STL STL Algorithm for C + +-Find algorithm (2)