游戏开发论坛

 找回密码
 立即注册
搜索
查看: 6471|回复: 1

boost之1.minmax

[复制链接]

56

主题

94

帖子

98

积分

注册会员

Rank: 2

积分
98
发表于 2010-8-14 20:47:00 | 显示全部楼层 |阅读模式
发一系列关于boost库的使用文章以备使用
//! boost库引导1.minmax
#include <list>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <boost/algorithm/minmax.hpp>
#include <boost/algorithm/minmax_element.hpp>
using
namespace std;
inline void Print(int i)
{
    std::cout<<i<<std::endl;  
}

inline int Rand()
{
    return rand()%10;      
}

int main()
{
    list<int> l;
    typedef list<int>::const_iterator iterator;
    //! 使用给定泛函子生成12个随机数并推入链表
    generate_n(front_inserter(l),12,Rand);
    std::for_each(l.begin(),l.end(),Print);
    std::cout<<"list size is:"<<l.size()<<std::endl;
    //! 获取给定序列的对大最小值,返回为std::pair<..,..>
    pair<iterator,iterator> result = boost::minmax_element(l.begin(),l.end());
    cout<<"the smallest element is:"<<*(result.first)<<endl;
    cout<<"the largest element is:"<<*(result.second)<<endl;
    //! 获取第一个最小元素
    iterator minitr = boost::first_min_element(l.begin(),l.end());
    cout<<"first min element is:"<<*minitr<<endl;
    system(&quotAUSE");
    return
1;
}

//! 后论:似乎没看到什么强大的功能
//!ccsdu2004

0

主题

50

帖子

143

积分

禁止发言

积分
143
发表于 2016-4-13 10:44:17 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-4-28 16:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表