| 
 | 
 
发一系列关于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(" AUSE"); 
    return 
1; 
} 
 
//! 后论:似乎没看到什么强大的功能 
//!ccsdu2004 |   
 
 
 
 |