發一系列關于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("PAUSE");
return 1;
}
//! 后論:似乎沒看到什么強大的功能
//!ccsdu2004