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 }

  • 相关阅读:
    Struts2拦截器(Interceptor)
    在ORACLE中实现SELECT TOP N
    eclipse搭配Resin开发Struts应用之环境篇
    Struts2中有关strutsdefault.xml,struts.xml,struts.properties文件详解
    iframe自适应加载的页面高度
    struts2的action中获得request response session 对象
    Win32环境下的Tomcat5.5.17与apache2.2的集群
    故事,幽默,脑筋急转弯
    5岁的女儿让老爸帮她做某事......
    解决WIN2003不能玩CS1.5
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2067400.html
Copyright © 2011-2022 走看看