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. Backup and Recovery Basics1

    一.Backup and Recovery Overview 1.Backup and Recovery Overview 1.1 What is Backup and Recovery? 一般,备份 ...

  2. 常用的Http组件

    日常生活中,我们接触最多的Http组件就是浏览器了!但是,还有其他也很重要的组件,下面容我慢慢盘点: 1.代理服务器 代理服务器就是帮助我们发送请求报文,接受响应报文的服务器.对web服务器而言,代理 ...

  3. linux用户密码生成

    linux账户保存在/etc/passwd,密码保存在/etc/shadow. 通过man 5 passwd,man 5 shadow可查看文件中各字段含义. encrypted password   ...

  4. 谈谈 epmd

    在<Erlang/OTP 并发编程实战>中,对 epmd 有如下描述: epmd  代表 Erlang 端口映射守护进程(Erlang Port Mapper Daemon). 每启动一个 ...

  5. 基于 UML 的业务建模举例

    简介: 对于管理流程咨询项目.大型信息化建设项目和套装管理软件实施项目,对业务环境的分析和理解对项目的成功至关重要.系统.全面理解 IT 系统所处的业务环境,可以帮助 IT 系统能提供正确系统功能,并 ...

  6. java中.currentTimeMillis的用法和含义

    用法:可以用法获取当前时间的毫秒数,可以通过毫秒数进行时间比较,时间转化以及时间格式化等.public class SystemTime {public static void main(String ...

  7. winform 的 checklistbox动态绑定并选中值

    绑定的代码:这里绑定的是一个泛型 BLL.PowerBLL powerbll = new BLL.PowerBLL(); checkpower.DataSource = powerbll.GetAll ...

  8. hdu 1078 FatMouse and Cheese【dp】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:每次仅仅能走 横着或竖着的 1~k 个格子.求最多能吃到的奶酪. 代码: #include ...

  9. Failed to load the JNI shared library jvm.dl

    . 原因1:该目录下jvm.dll不存在 2 解决办法:重新安装jdk或者jre并配置好环境变量.copy一个jvm.dll放在该目录下 3 原因2:eclipse的版本与jdk或者jre版本不一致 ...

  10. python静态网页爬虫之xpath

    常用语句: 1.starts-with(@属性名称,属性字符相同部分)使用情形: 以相同的字符开头 <div id = 'test-1'>需要的内容1</div> <di ...