zoukankan      html  css  js  c++  java
  • C++ 在容器A中查找最后出现的容器B中的元素,并返回iterator(find_end)

    #include <iostream>     // cout
    #include <algorithm>    // find_end
    #include <vector>       // vector
    using namespace std; 
    bool myfunction (int i, int j) {
      return (i==j);
    }
    
    int main () {
      int myints[] = {1,2,3,4,5,1,2,3,4,5};
      vector<int> haystack (myints,myints+10);
    
      int needle1[] = {1,2,3};
    
      // using default comparison:
      vector<int>::iterator it;
      it = find_end (haystack.begin(), haystack.end(), needle1, needle1+3);
    
      if (it!=haystack.end())
        cout << "needle1 last found at position " << (it-haystack.begin()) << '
    ';
    
      int needle2[] = {4,5,1};
    
      // using predicate comparison:
      it = find_end (haystack.begin(), haystack.end(), needle2, needle2+3, myfunction);
    
      if (it!=haystack.end())
        cout << "needle2 last found at position " << (it-haystack.begin()) << '
    ';return 0;
    }
  • 相关阅读:
    [kuangbin带你飞]专题1-23
    ES code study
    ES特点
    CENTOS7命令
    ES单机版安装
    ES安装手册
    数据库三大范式(1NF,2NF,3NF)及ER图
    win10下Spark的环境搭建
    MySQL安装详细图解整理
    MySQL中format()函数
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9823550.html
Copyright © 2011-2022 走看看