STL学习笔记----16.STL算法之 (数值算法)
2012-03-08 13:54
363 查看
一. 概述
用来处理数值的算法,需要加上头文件 #include<numberic>
二. 加工运算后产生结果
1. 对序列进行某种运算
1. 将相对值转换成绝对值
用来处理数值的算法,需要加上头文件 #include<numberic>
accumulate() | 组合所有元素(求总和,求乘积...) |
inner_product() | 组合两区间内的所有元素 |
adjacent_difference() | 将每个元素和其前一元素组合 |
partial_sum() | 将每个元素和其先前的所有元素组合 |
1. 对序列进行某种运算
//计算initValue和区间[beg, end)内所有元素的总和 //也就是: initValue + a1 + a2 + a3 +... T accumulate (InputIterator beg, InputIterator end, T initValue) //也就是:initValue op a1 op a2 ... //比如 op 是 乘,则为:initValue * a1 * a2 * a3... T accumulate (InputIterator beg. InputIterator end, T initValue, BinaryFunc op)2. 计算两序列内积
//返回[beg, end)区间和beg2为起始的区间的对应元素组的内积 //initValue + (a1*b1) + (a2*b2) + (a3*b3) + ... T inner_product (InputIterator1 beg1, InputIterator1 end1, InputIterator2 beg2, T initValue) //initValue op1 (a1 op2 b1) op1 (a2 op2 b2) op1 ... T inner_product (InputIterator1 beg1. InputIterator1 end1, InputIterator2 beg2, T initValue, BinaryFunc op1, BinaryFunc op2)三. 相对值和绝对值之间的转换
1. 将相对值转换成绝对值
//计算区间[sourceBeg, sourceEnd)中每个元素的部分和,然后写入destBeg //a1, a1+a2, a1+a2+a3, ... OutputIterator partial_sum (InputIterator sourceBeg, InputIterator sourceEnd, OutputIterator destBeg) //a1, a1 op a2, a1 op a2 op a3, ... OutputIterator partial_sum (InputIterator sourceBeg, InputIterator sourceEnd, OutputIterator destBeg, BinaryFunc op)2. 将绝对值转换成相对值
//计算区间[sourceBeg, sourceEnd)中每一个元素前趋差,然后写destBeg //a1, a2-a1, a3-a2, a4-a3, ... OutputIterator adjacent_difference (InputIterator sourceBeg, InputIterator sourceEnd, OutputIterator destBeg) //a1, a2 op a1, a3 op a2, a4 op a3, ... OutputIterator adjacent_difference (InputIterator sourceBeg, InputIterator sourceEnd, OutputIterator destBeg, BinaryFunc op)
相关文章推荐
- STL学习笔记----16.STL算法之 (数值算法)
- STL学习笔记--数值算法
- C++ Primer 学习笔记_45_STL实践与分析(19)--泛型算法的结构
- STL学习笔记之算法--algorithmn
- STL学习笔记----11.STL算法之 (变动性算法)
- STL学习笔记— —算法
- SGI STL学习笔记(3):copy算法实现细节
- STL学习笔记之 算法(构造堆等)
- C++ Primer 学习笔记_45_STL实践与分析(19)--建筑常规算法
- STL学习笔记----10.STL算法之 (非变动性算法)
- C++ Primer 学习笔记_46_STL实践与分析(20)--容器特有的算法
- C++精华(STL)学习笔记之算法
- STL学习笔记--算法
- STL的内观排序(introsort)算法学习笔记
- 泛型编程与STL学习笔记之算法
- STL学习笔记----13.STL算法之 (变序性算法)
- STL学习笔记----15.STL算法之 (已序区间算法)
- STL源码剖析学习十二:算法之数值算法
- STL学习笔记----14.STL算法之 (排序算法)
- STL学习笔记----14.STL算法之 (排序算法)