准备开个帖子记录一下algorithm头文件中常用的函数。
1. for_each( vec.begin(), vec.end(), function() );
template<typename InputIterator, typename Function> Function for_each(InputIterator beg, InputIterator end, Function f) { while(beg != end) f(*beg++); }
2. count/count_if
注:此两个函数复杂度是线性的,适用于小规模运算。
count( vec.begin(), vec.end(), value ); //统计vec中值为value的元素数目 count_if( vec.begin(), vec.end(), cmp ); count_if( vec.begin(), vec.end(), cmp, value );-------持续更新------