• 通过仿函数for_each操作

     vector<int> myv{ ,,,, };
    list<double> db{ 1.1,2.2,3.3,4.4,5.5 }; //循环算法,算法的泛型
    print p = for_each(db.begin(), db.end(), print());
    cout << p.count << endl;
  • find_if查找算法
     //查找算法
    auto it = find(myv.begin(), myv.end(), );
    cout << *it << endl;
  • find_if与lambda结合
     //寻找第一个偶数的位置,返回0就是找到的
    auto it = find_if(myv.begin(), myv.end(), [](int x)->bool
    {
    if (x % == )
    {
    return ;
    }
    else
    {
    return ;
    }
    }); if (it != myv.end())
    {
    cout << *it << " pos=" << it - myv.begin() << endl;
    }
  • adjacent_find处理相邻的两个数据
     list <int> mylist{ ,,,,,,, };
    //查找相邻的两个元素相等的位置(adjacent_find处理相邻的两个数据)
    auto it = adjacent_find(mylist.begin(), mylist.end());
    if (it != mylist.end())
    {
    cout << *it << endl;
    it++;
    cout << *it << endl;
    }
  • adjacent_find与lambda结合
     //寻找第一个奇偶性不同的
    auto it = adjacent_find(mylist.begin(), mylist.end(), [](int x,int y)->bool
    {
    if ((x - y) % == )
    {
    return ;
    }
    else
    {
    return ;
    }
    });
    if (it != mylist.end())
    {
    cout << *it << endl;
    it++;
    cout << *it << endl;
    }
  • find_first_of寻找第一个集合在第二个集合中出现的第一个数据
     char *str1 = "";
    char *str2 = "abcdefg123";
    //寻找在string1中第一个出现在string2的字符
    char *p = find_first_of(str1, str1 + strlen(str1), str2, str2 + strlen(str2));
    cout << *p << endl; vector<int> myint1{ ,,,, };
    vector<int> myint2{ ,,,, };
    auto it = find_first_of(myint1.begin(), myint1.end(), myint2.begin(), myint2.end());
    cout << *it << endl;
  • count与count_if查询数据个数
     vector<int> myint{ ,,,,,,,,, };
    int count1 = count(myint.begin(), myint.end(), );
    cout << count1 << endl; //查询所有小于4的元素的个数
    int count2 = count_if(myint.begin(), myint.end(), [](int x)
    {
    if (x < )
    {
    return ;
    }
    else
    {
    return ;
    }
    });
    cout << count2 << endl;
  • mismatch判断两个集合是否相等
     vector<int> myint1{ ,,,,,,,,, };
    vector<int> myint2{ ,,,,,,,,, }; auto it = mismatch(myint1.begin(), myint1.end(), myint2.begin());
    if (it.first == myint1.end() && it.second == myint2.end())
    {
    cout << "相等" << endl;
    }
    else
    {
    //first是第一个容器不匹配的位置(可能为空),second是第二个容器不匹配的位置(可能为空)
    cout << "不相等" << endl;
    cout << *(it.first) <<" " << *(it.second) << endl;
    }
     char *s1[] = { "abc","acv","adf","oop" };
    char *s2[] = { "abc","acv","adf","oop","" };
    auto it = mismatch(s1, s1 + , s2, [](const char* str1,const char* str2)
    {
    if (strcmp(str1, str2) == )
    {
    return ;
    }
    else
    {
    return ;
    }
    }); if (it.first == s1 + sizeof(s1)/sizeof(s1[]) && it.second == s2 + sizeof(s2) / sizeof(s2[]))
    {
    cout << "相等" << endl;
    }
    else
    {
    //first是第一个容器不匹配的位置(可能为空),second是第二个容器不匹配的位置(可能为空)
    cout << "不相等" << endl;
    //cout << *(it.first) << " " << *(it.second) << endl;
    }
  • equal判断是否是一样的集合
    
         vector<int> myv1{ ,,,, };
    vector<int> myv2{ -,,-,,- }; //判断绝对值知否相等
    if (equal(myv1.begin(), myv1.end(), myv2.begin(), [](int a, int b) ->bool
    {
    if (a == abs(b) || b == abs(a))
    {
    return ;
    }
    else
    {
    return ;
    }
    }))
    {
    cout << "相等" << endl;
    }
    else
    {
    cout << "不相等" << endl;
    }
  • search判断有没有连续一样的部分
     vector<int> myv1{ , };
    vector<int > myv2{ ,,,, }; //判断有没有连续相等的子集
    auto it = search(myv1.begin(), myv1.end(), myv2.begin(), myv2.end()); if (it == myv1.end())
    {
    cout << "是子集" << endl;
    }
    else
    {
    cout << "不是子集" << endl;
    }
  • search_n判断有没有连续一样的数据
     vector<int> myv1{ ,,,,,, };
    
         //判断有没有连续相等的数据
    auto it = search_n(myv1.begin(), myv1.end(),, ); if (it == myv1.end())
    {
    cout << "有" << endl;
    }
    else
    {
    cout << "没有" << endl;
    }
  • 从反向寻找一个集合在另一个集合中出现的位置
     vector<int> myv2{ ,,,,,, };
    vector<int> myv3{ , };
    //在myv2中从后往前找myv3所在的位置
    auto it = find_end(myv2.begin(), myv2.end(), myv3.begin(), myv3.end()); if(it != myv2.end())
    {
    cout << *it << " " << it - myv2.begin() << endl;
    }

25.不改变原生数据的STL algorithm的更多相关文章

  1. SharePoint 2010 升级到2013时间 为了确保用户可以连接,但无法改变升级数据

    SharePoint 2010 升级到2013时间 为了确保用户可以连接,但无法改变升级数据 我总结的步骤 红色请注意它们的含义. 步骤1:连接到SQL DBS 上的SharePoint 2010数据 ...

  2. 【ArcGIS 10.2新特性】ArcGIS 10.2将PostgreSQL原生数据发布为要素服务

    1.ArcGIS 10.2支持原生数据发布为要素服 有没有将自己已有的空间数据发布为要素服务的需求?有没有将非Esri空间数据类型的数据作为服务在Web端展示的需求?     ArcGIS 10.2 ...

  3. 14Flutter StatefulWidget有状态组件、页面上绑定数据、改变页面数据、实现计数器功能、动态列表

    /** * Flutter StatefulWidget有状态组件.页面上绑定数据.改变页面数据 * 在Flutter中自定义组件其实就是一个类,这个类需要继承StatelessWidget/Stat ...

  4. 使用 Iceberg on Kubernetes 打造新一代云原生数据湖

    背景 大数据发展至今,按照 Google 2003年发布的<The Google File System>第一篇论文算起,已走过17个年头.可惜的是 Google 当时并没有开源其技术,& ...

  5. Fluid + GooseFS 助力云原生数据编排与加速快速落地

    前言 Fluid 作为基于 Kubernetes 开发的面向云原生存算分离场景下的数据调度和编排加速框架,已于近期完成了 v0.6.0 版本的正式发布.腾讯云容器 TKE 团队一直致力于参与 Flui ...

  6. STL algorithm 头文件下的常用函数

    algorithm 头文件下的常用函数 1. max(), min()和abs() //max(x,y)和min(x,y)分别返回x和y中的最大值和最小值,且参数必须时两个(可以是浮点数) //返回3 ...

  7. Flutter StatefulWidget 有状态组件、页面上绑定数据、改变页面数据

    在 Flutter 中自定义组件其实就是一个类,这个类需要继承 StatelessWidget/StatefulWidget. StatelessWidget 是无状态组件,状态不可变的 widget ...

  8. php 封装原生数据导入的方法(csv文件格式)

    //前端---部分代码 <form class="form-inline" style="margin-top: 20px" method="p ...

  9. StatelessWidget 无状态组件 StatefulWidget 有状态组件 页面上绑定数据、改变页面数据

    一.Flutter 中自定义有状态组件 在 Flutter 中自定义组件其实就是一个类,这个类需要继承 StatelessWidget/StatefulWidget. StatelessWidget ...

随机推荐

  1. [Angular] Fetch non-JSON data by specifying HttpClient responseType in Angular

    By default the new Angular Http client (introduced in v4.3.1) uses JSON as the data format for commu ...

  2. HDU 5410(2015多校10)-CRB and His Birthday(全然背包)

    题目地址:HDU 5410 题意:有M元钱,N种礼物,若第i种礼物买x件的话.会有Ai*x+Bi颗糖果,现给出每种礼物的单位价格.Ai值与Bi值.问最多能拿到多少颗糖果. 思路:全然背包问题. dp[ ...

  3. POJ-3264-Balanced Lineup-单点更新

    题目链接:id=3264">http://poj.org/problem? id=3264 这是一个单点更新的模板题,就不详解了,HDU敌兵布阵那题我有详解:链接:http://blo ...

  4. Android用canvas画哆啦A梦

    先上图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...

  5. Linux部署之批量自动安装系统之DHCP篇

    1.         安装:yum install dhcp   2.         Ip配置信息   3.         Dhcp配置文件如下   4.         配置完后检查语法是否错误 ...

  6. 响应式流API的构建基础

    下面三个重要的概念是响应式流API的构建基础: 发布者是事件的发送方,可以向它订阅. 订阅者是事件订阅方. 订阅将发布者和订阅者联系起来,使订阅者可以向发布者发送信号. http://www.info ...

  7. SpringCloud学习笔记(18)----Spring Cloud Netflix之服务网关Zuul原理

    1. Zuul的工作机制 Zuul提供了一个框架,可以对过滤器进行动态的加载,编译,运行.过滤器之间没有直接的相互通信,他们是通过一个RequestContext的静态类来进行数据传递的.Requet ...

  8. js的调试和优化

    一.常见的错误和异常 1.拼写错误 拼写错误,可以有代码的高亮来发现. 2.访问不存在的变量 3.括号不匹配 养成规范的编写习惯,适当应用Tab.空行等. 4.字符串和变量链接错误 采用多加括号来进行 ...

  9. 关于Scrapy爬虫项目运行和调试的小技巧(下篇)

    前几天给大家分享了关于Scrapy爬虫项目运行和调试的小技巧上篇,没来得及上车的小伙伴可以戳超链接看一下.今天小编继续沿着上篇的思路往下延伸,给大家分享更为实用的Scrapy项目调试技巧. 三.设置网 ...

  10. CSS3中的transition

    W3C标准中对CSS3的transition是这样描述的: CSS的transition允许CSS的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击,获得焦点,被点击或对元素任何改变中触发, ...