STL里的算法已经很好了,在boost里有几个小的算法

1.BOOST_FOREACH使用方法,定义一个容器里内部类型数据,容器作为参数传递。

#include <iostream>
#include <string>
#include <vector>
#include <boost/assign.hpp>
#include <boost/foreach.hpp>
using namespace std;
using namespace boost::assign; int main()
{ vector<int> v = list_of(1)(2)(3)(4)(5);
BOOST_FOREACH(int x,v)
{
cout << x << ",";
}
cout << endl;
string str("boost foreach");
BOOST_FOREACH(char c,str)
{
cout << c << "-";
}
cout << endl;
return 0;
}

2.minmax同时返回两个数最大值和最小值,返回类型为tuple,使用方法:

#include <iostream>
#include <string>
#include <vector>
#include <boost/assign.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/algorithm/minmax.hpp>
#include <boost/tuple/tuple.hpp>
using namespace std;
using namespace boost::assign; int main()
{ BOOST_AUTO(x,boost::minmax(100,200));
cout << x.get<1>() << " " << x.get<0>() <<endl;
return 0;
}

3.minmax_element()用于找出容器中的最大值和最小值。

#include <iostream>
#include <string>
#include <vector>
#include <boost/assign.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/algorithm/minmax_element.hpp>
#include <boost/tuple/tuple.hpp>
using namespace std;
using namespace boost::assign;
using namespace boost; int main()
{
vector<int> v = list_of(633)(90)(67)(83)(2);
BOOST_AUTO(x,boost::minmax_element(v.begin(),v.end()));
cout << "min: " << *x.first <<endl;
cout << "max: " << *x.second <<endl; return 0;
}

boost之算法的更多相关文章

  1. boost字符串算法

    boost::algorithm简介 2007-12-08 16:59 boost::algorithm提供了很多字符串算法,包括: 大小写转换: 去除无效字符: 谓词: 查找: 删除/替换: 切割: ...

  2. 19.boost A*算法

    #include <iostream> #include <string> #include <utility> #include <vector> # ...

  3. 使用 AdaBoost 元算法提高分类器性能

    前言 有人认为 AdaBoost 是最好的监督学习的方式. 某种程度上因为它是元算法,也就是说它会是几种分类器的组合.这就好比对于一个问题能够咨询多个 "专家" 的意见了. 组合的 ...

  4. 第九篇:使用 AdaBoost 元算法提高分类器性能

    前言 有人认为 AdaBoost 是最好的监督学习的方式. 某种程度上因为它是元算法,也就是说它会是几种分类器的组合.这就好比对于一个问题能够咨询多个 "专家" 的意见了. 组合的 ...

  5. kaggle 竞赛之套路

    图片数据:卷积还是王道,有几个比较通用性的框架被人拿来改来改去 非图片特征数据:用分类: boost系列算法:牛逼的框架实现 xgboost AdaBoost算法针对不同的训练集训练同一个基本分类器( ...

  6. [转]C++学习–基础篇(书籍推荐及分享)

    C++入门 语言技巧,性能优化 底层硬货 STL Boost 设计模式 算法篇 算起来,用C++已经有七八年时间,也有点可以分享的东西: 以下推荐的书籍大多有电子版.对于技术类书籍,电子版并不会带来一 ...

  7. 编译器的未来——我们还需要C++么?

    在未来我们还需要纯C++开发模式么? 随着C++11的诞生,C++已经越来越臃肿,从03的时候就觉得C++实在是太复杂了.以一个合格C++程序员的标准来简单的来说3-5年略有小成,5-8年才可以说自己 ...

  8. solr 使用edismax来控制评分

    如何控制评分 如果设置了sort字段,那么将会按照sort字段的顺序返回结果. 如果没有设置sort字段,那么将会根据相关度打分来排序.也就是说,相关度更高的排在前面. 如何来定制适合自身业务的排序打 ...

  9. C++ 著名程序库 概览

          本文转载自: http://ace.acejoy.com/thread-3777-1-1.html   1.C++各大有名库的介绍--C++标准库 2.C++各大有名库的介绍--准标准库B ...

随机推荐

  1. First MFC

    // stdafx.h : include file for standard system include files, // or project specific include files t ...

  2. Java synchronized详解(java 线程同步)

    http://www.cnblogs.com/devinzhang/archive/2011/12/14/2287675.html

  3. 如何理解HTTP协议的“无连接,无状态”特点

    是一个属于应用层的面向对象的协议,HTTP 协议一共有五大特点:1.支持客户/服务器模式;2.简单快速;3.灵活;4.无连接;5.无状态. 无连接 无连接的含义是限制每次连接只处理一个请求.服务器处理 ...

  4. 183.Wood Cut【hard】

    183.Wood Cut[hard] Given n pieces of wood with length L[i] (integer array). Cut them into small piec ...

  5. shell脚本之练习题

    设计一个shell程序,添加一个新组为class1,然后添加属于这个组的30个用户,用户名的形式为stdxx,其中xx从01到30. i=1 groupadd class1 while [ $i -l ...

  6. MySQL和hive对比表结构脚本

    #!/bin/bash source /etc/profile runlog='/tmp/zewei/check_schema_log' hive_database_schema=/tmp/hive_ ...

  7. python C PyObject

    #include"Python.h" //three ways : /* PyObject *MyFunction(PyObject *self, PyObject *args); ...

  8. 如何让git小乌龟工具TortoiseGit记住你的账号密码

    在使用小乌龟的过程中,发下每次push或者pull都要重复输入账号密码,非常麻烦. 如果能记住账号密码就好了,这样就省去了时间. 怎么设置记住密码 在[系统盘]:\Users[你的用户名]下面,有一个 ...

  9. ftp 下载最近一小时的文件

    #!/bin/bash #cd /home/ftptmp/ ftp -v -n 192.168.0.100 2121 <<EOF user  test  2009 binary cd OU ...

  10. IE6鼠标悬停Bug

    当鼠标放置于某个文字链接之上,文字或文字背景改变为其他颜色或样式的效果是我们最经常见到的鼠标悬停效果.在CSS中,这个效果靠伪元素:hover来实现,只不过在文字链接中:hover被应用在了锚点元素& ...