首页 > 编程语言 > 详细

1.4 算法 - algorithm

时间:2016-05-05 15:59:13      阅读:250      评论:0      收藏:0      [点我收藏+]

1)概述

技术分享

2)示例

技术分享

//algorithm  find演示 
#include <vector>
#include <algorithm>
#include <iostream> 
using namespace std;
 int main()  {
    //find算法示例
    int array[10] = {10,20,30,40};
    vector<int> v; v.push_back(1);
    v.push_back(2); v.push_back(3);
    v.push_back(4); vector<int>::iterator p;
    p = find(v.begin(),v.end(),3);
    if( p != v.end())
        cout << * p << endl; //输出3
        
    p = find(v.begin(),v.end(),9);
    if( p == v.end()) cout << "not found " << endl;
        p = find(v.begin()+1,v.end()-2,1); //整个容器:[1,2,3,4], 查找区间:[2,3) if( p != v.end()) 
    cout << * p << endl;
    int * pp = find( array,array+4,20);//数组名是迭代器 cout << * pp << endl;
}

 

1.4 算法 - algorithm

原文:http://www.cnblogs.com/by-dxm/p/5462111.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!