A simple program interprets the C ++ STL algorithm series II: Find

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 algorithm is used to find elements that are equal to a value. It searches for elements equal to the value on the iterator range [first, last). If the element referred to by the iterator ITER satisfies * iter = value, the iterator ITER is returned, if not found, return last.

Function prototype:

template<class InputIterator, class Type>   InputIterator find(      InputIterator _First,       InputIterator _Last,       const Type& _Val   );

Sample Code:

/*************************************** * **************************** Copyright (c) jerry Jiang * file name: Find. CPP * Author: Jerry Jiang * Create Time: 2011-9-29 0:03:25 * mail: jbiaojerry@gmail.com * blog: http://blog.csdn.net/jerryjbiao * Description: simple program c ++ STL algorithm series II * non variable algorithm: find the container element "find ************************************ * ****************************/# include <algorithm> # include <List> # include <iostream> using namespace STD; int main () {list <int> ilist; For (size_t I = 0; I <10; ++ I) {ilist. push_back (I + 1);} ilist. push_back (10); List <int >:: iterator ilocation = find (ilist. begin (), ilist. end (), 10); If (ilocation! = Ilist. end () {cout <"find element 10" <Endl ;}cout <"the previous element is:" <* (-- ilocation) <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.