zoukankan      html  css  js  c++  java
  • C++类属性算法search

    类属算法search的功能是:给定两个迭代器区间,将后一个区间内的对象作为一个子序列,并在前一个区间内查找出现该子序列的第一个位置。

    1 // Illustrating the generic equal and mismatch algorithms
    2 #include <iostream>
    3 #include <cassert>
    4 #include <algorithm>
    5 #include <string>
    6 #include <list>
    7 #include <deque>
    8 #include <vector>
    9 using namespace std;
    10
    11 int main()
    12 {
    13 cout << "Illustrating the generic equal "
    14 << "and mismatch algorithms." << endl;
    15 list<string> driver_list;
    16 vector<string> vec;
    17 deque<string> deq;
    18
    19 driver_list.insert(driver_list.end(), "Clark");
    20 driver_list.insert(driver_list.end(), "Rindt");
    21 driver_list.insert(driver_list.end(), "Senna");
    22
    23 vec.insert(vec.end(), "Clark");
    24 vec.insert(vec.end(), "Rindt");
    25 vec.insert(vec.end(), "Senna");
    26 vec.insert(vec.end(), "Berger");
    27
    28 deq.insert(deq.end(), "Clark");
    29 deq.insert(deq.end(), "Berger");
    30
    31 // Show that driver_list and the first 3 elements of
    32 // vec are equal in all corresponding positions:
    33 assert (equal(driver_list.begin(), driver_list.end(),
    34 vec.begin()));
    35
    36 // Show that deq and the first 2 elements of driver_list
    37 // are not equal in all corresponding positions:
    38 assert (!equal(deq.begin(), deq.end(),
    39 driver_list.begin()));
    40
    41 // Find the corresponding positions in deq and driver_list
    42 // at which unequal elements first occur:
    43 pair<deque<string>::iterator, list<string>::iterator>
    44 pair1 = mismatch(deq.begin(), deq.end(),
    45 driver_list.begin());
    46
    47 if (pair1.first != deq.end())
    48 cout << "First disagreement in deq and driver_list:\n "
    49 << *(pair1.first) << " and " << *(pair1.second)
    50 << endl;
    51 return 0;
    52 }

  • 相关阅读:
    IOS开发中实现UITableView按照首字母将集合进行检索分组
    IOS开发中设置导航栏主题
    IOS中使用.xib文件封装一个自定义View
    IOS中将字典转成模型对象
    WindowsPhone8中LongListSelector的扩展解决其不能绑定SelectdeItem的问题
    WindowsPhone8.1 开发-- 二维码扫描
    tomcat 开机自启
    redis ubuntu 开机自启
    webStorm 中使用 supervisor 调试
    ubuntu 14.04 tab失效问题
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2067400.html
Copyright © 2011-2022 走看看