STL学習ノート----16.STLアルゴリズム(数値アルゴリズム)
2052 ワード
一.概要
数値を処理するためのアルゴリズムには、上のファイルを追加する必要があります.
accumulate()
すべての要素を組み合わせます.合計を求め、積を求めます.
inner.プロジェクト
二つの区間のすべての要素を組み合わせます.
adjacent_ディfference()
各要素を前の要素と組み合わせる
パーティーsum()
各要素と以前のすべての要素を組み合わせます.
二.加工演算後の結果
1.シーケンスに対して何らかの演算を行う
1.相対値を絶対値に変換する
数値を処理するためのアルゴリズムには、上のファイルを追加する必要があります.
accumulate()
すべての要素を組み合わせます.合計を求め、積を求めます.
inner.プロジェクト
二つの区間のすべての要素を組み合わせます.
adjacent_ディfference()
各要素を前の要素と組み合わせる
パーティー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.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)