A simple program interprets 12 of the C ++ STL algorithm series: find_end

Source: Internet
Author: User

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 find_end algorithm searches for the Child sequence that matches the last sequence with the other sequence. There are two function prototypes. In the iterator range [first1, last1), find the child sequence that matches the iterator range [first2, last2) element, returns the iterator or last1 of the first element.

Function prototype:

template<class ForwardIterator1, class ForwardIterator2>   ForwardIterator1 find_end(      ForwardIterator1 _First1,       ForwardIterator1 _Last1,      ForwardIterator2 _First2,       ForwardIterator2 _Last2   );template<class ForwardIterator1, class ForwardIterator2, class Pr>   ForwardIterator1 find_end(      ForwardIterator1 _First1,       ForwardIterator1 _Last1,      ForwardIterator2 _First2,       ForwardIterator2 _Last2,      BinaryPredicate _Comp   ); 

Example program:

/*************************************** * **************************** Copyright (c) jerry Jiang * file name: find_end.cpp * Author: Jerry Jiang * Create Time: 2011-10-12 20:07:20 * mail: jbiaojerry@gmail.com * blog: http://blog.csdn.net/jerryjbiao * description: A simple program interprets 12 * Non-Variable Algorithms in the C ++ STL algorithm series: find_end ********************************** * *******************************/# include <ALG Orithm >#include <vector >#include <iostream> using namespace STD; int main () {vector <int> V1; v1.push _ back (5 ); v1.push _ back (-2); v1.push _ back (4); v1.push _ back (3); v1.push _ back (-2); v1.push _ back (4 ); v1.push _ back (8); v1.push _ back (-2); v1.push _ back (4); v1.push _ back (9); vector <int >:: const_iterator ITER; cout <"V1:"; for (iter = v1.begin (); iter! = V1.end (); ++ ITER) {cout <* ITER <";}cout <Endl; vector <int> V2; v2.push _ back (-2 ); v2.push _ back (4); cout <"V2:"; for (iter = v2.begin (); iter! = V2.end (); ++ ITER) {cout <* ITER <"" ;}cout <Endl; vector <int >:: iterator iloaction; iloaction = find_end (v1.begin (), v1.end (), v2.begin (), v2.end (); If (iloaction! = V1.end () {cout <"V1 finds the last child sequence that matches V2. The starting position is:" <"V1 [" <iloaction-v1.begin () <"]" <Endl;} return 0 ;}

**************************************** **************************************** **************************************** *******

C ++ classic bibliography index and resource download:Http://blog.csdn.net/jerryjbiao/article/details/7358796

**************************************** **************************************** **************************************** ********

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.