由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - ANY IDEA?
相关主题
帮我看看这两个题目回答How to handle the return type of container.size() in C++
C++ template Questions问个stl iterator的问题
大家来讨论一下c++吧一道STL面试题
问一道C++ template的面试题C++在vector里找>50的数,怎么找?
std::list如何检测环?面完G的电面了,忐忑
请教为什么这段程序运行不work?(doubly linked list) (转载求教:这个程序为什么不能编译?
问个题一道A家店面题求解
hadoop的combiner和partitioner的顺序是什么呢?包子求大牛:C++的list iterator实现
相关话题的讨论汇总
话题: reduce话题: container话题: typename话题: function话题: fn
进入JobHunting版参与讨论
1 (共1页)
a********y
发帖数: 31
1
怎么实现?
{for (int i=c.begin();i<=c.end();i++)
fn;}
对吗?觉得有些不对!

implement the Reduce function using templates.
The Reduce fn applies a function of two arguments cumulatively
to the items of an STL container, from begin() to end(), so as
to reduce the sequence to a single value. For example,
Reduce(, std::plus())
should calculate ((((1+2)+3)+4)+5).
class NotEnoughElements {};
template
x***y
发帖数: 633
2
typedef typename Container::iterator Citerator;
typedef typename Container::value_type Vtype;
if(c.size()==0)
return Vtype();
Vtype finalValue=*c.begin();
for(Citerator iter=c.begin()+1; iter!=C.end(); iter++){

fn(finalValue, *iter);
}
return finalValue;

【在 a********y 的大作中提到】
: 怎么实现?
: {for (int i=c.begin();i<=c.end();i++)
: fn;}
: 对吗?觉得有些不对!
:
: implement the Reduce function using templates.
: The Reduce fn applies a function of two arguments cumulatively
: to the items of an STL container, from begin() to end(), so as
: to reduce the sequence to a single value. For example,
: Reduce(, std::plus())

1 (共1页)
进入JobHunting版参与讨论
相关主题
包子求大牛:C++的list iterator实现std::list如何检测环?
攒人品 贴个Bloomberg phone interview.请教为什么这段程序运行不work?(doubly linked list) (转载
问个static STL container的问题问个题
array contains two integer that sum up to 7hadoop的combiner和partitioner的顺序是什么呢?
帮我看看这两个题目回答How to handle the return type of container.size() in C++
C++ template Questions问个stl iterator的问题
大家来讨论一下c++吧一道STL面试题
问一道C++ template的面试题C++在vector里找>50的数,怎么找?
相关话题的讨论汇总
话题: reduce话题: container话题: typename话题: function话题: fn