STL学习笔记----16.STL算法之 (数值算法)
2013-10-17 14:39
405 查看
一. 概述
用来处理数值的算法,需要加上头文件 #include<numberic>
二. 加工运算后产生结果
1. 对序列进行某种运算
[cpp]
view plaincopyprint?
//计算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. 计算两序列内积
[cpp]
view plaincopyprint?
//返回[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. 将相对值转换成绝对值
[cpp]
view plaincopyprint?
//计算区间[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. 将绝对值转换成相对值
[cpp]
view plaincopyprint?
//计算区间[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)
用来处理数值的算法,需要加上头文件 #include<numberic>
accumulate() | 组合所有元素(求总和,求乘积...) |
inner_product() | 组合两区间内的所有元素 |
adjacent_difference() | 将每个元素和其前一元素组合 |
partial_sum() | 将每个元素和其先前的所有元素组合 |
1. 对序列进行某种运算
[cpp]
view plaincopyprint?
//计算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)
//计算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. 计算两序列内积
[cpp]
view plaincopyprint?
//返回[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)
//返回[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. 将相对值转换成绝对值
[cpp]
view plaincopyprint?
//计算区间[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)
//计算区间[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. 将绝对值转换成相对值
[cpp]
view plaincopyprint?
//计算区间[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)
//计算区间[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学习笔记--数值算法
- STL学习笔记----11.STL算法之 (变动性算法)
- STL学习笔记之 算法(构造堆等)
- C++ Primer 学习笔记_46_STL实践与分析(20)--容器特有的算法
- STL学习笔记--算法
- STL学习笔记----10.STL算法之 (非变动性算法)
- 泛型编程与STL学习笔记之算法
- C++精华(STL)学习笔记之算法
- STL学习笔记----15.STL算法之 (已序区间算法)
- STL的内观排序(introsort)算法学习笔记
- STL学习笔记----14.STL算法之 (排序算法)
- STL源码剖析学习十二:算法之数值算法
- STL学习笔记----13.STL算法之 (变序性算法)
- 【算法学习笔记】57. 前缀树 字典序优化技巧 STL学习 SJTU OJ 1366 前缀匹配
- STL学习笔记----13.STL算法之 (变序性算法)
- STL学习笔记之sort算法
- STL学习笔记----14.STL算法之 (排序算法)
- STL学习笔记----12.STL算法之 (移除性算法)
- 【ML学习笔记】13:k-近邻算法做数值特征分类