c++算数生成算法(C + + arithmetic generation algorithm)

算术生成算法属于小型算法,使用时包含的头文件为 #include <numeric>

accumulate // 计算容器元素累计总和fill // 向容器中添加元素

accumulate 功能描述:计算区间内 容器元素累计总和函数原型:accumulate(iterator beg, iterator end, value,(__binary_op));// 计算容器元素累计总和// beg 开始迭代器// end 结束迭代器// value 起始值

//__binary_op重写函数对象

stl中accumulate的实现如下,因为它的默认函数中()内为init值和一个first迭代器,所以重写时函数第一个输入为求和结果变量,第二个输入为自定义数据类型

fill 功能描述:向容器中填充指定的元素

函数原型:fill(iterator beg, iterator end, value);// 向容器中填充元素// beg 开始迭代器// end 结束迭代器// value 填充的值

————————

The arithmetic generation algorithm is a small algorithm, and the header file included when using is #include & lt; numeric>

Calculate / / calculate the cumulative sum of container elements fill / / add elements to the container

Calculate Function Description: calculate the cumulative sum of the elements of the interval content container. Function prototype: calculate (iterator beg, iterator end, value, (_binary_op))// Calculate the cumulative sum of container elements / / beg start iterator / / end end iterator / / value start value

//__ binary_ OP override function object

The implementation of calculate in STL is as follows. Because the default function () contains the init value and a first iterator, the first input of the function is the summation result variable and the second input is the user-defined data type

Fill function description: fill the container with the specified elements

Function prototype: fill (iterator beg, iterator end, value)// Fill the container with elements / / beg starts the iterator / / end ends the iterator / / value fills the value