The following two algorithms enable you to convert a sequence of relative values into a sequence of
absolute values, and vice versa.
Converting Relative Values into Absolute Values
OutputIterator
partial_sum (InputIterator sourceBeg, InputIterator sourceEnd,
OutputIterator destBeg)
OutputIterator
partial_sum (InputIterator sourceBeg, InputIterator sourceEnd,
OutputIterator destBeg, BinaryFunc op)
• The first form computes the partial sum for each element in the source range [sourceBeg,
sourceEnd) and writes each result to the destination range starting with destBeg.
• The second form calls op for each element in the source range [sourceBeg,sourceEnd) combined
with all previous values and writes each result to the destination range starting with destBeg.
• Thus, for the values
a1 a2 a3 ...
they compute either
a1, a1 + a2, a1 + a2 + a3, ...
or
a1, a1 op a2, a1 op a2 op a3, ...
respectively.
• Both forms return the position after the last written value in the destination range (the first element
that is not overwritten).
• The first form is equivalent to the conversion of a sequence of relative values into a sequence
of absolute values. In this regard, algorithm partial_sum() is the complement of algorithm
adjacent_difference() (see page 628).
• The source and destination ranges may be identical.
• The caller must ensure that the destination range is big enough or that insert iterators are used.
• op should not modify the passed arguments.
• Complexity: linear (numElems calls of operator + or op(), respectively).
The following program demonstrates some examples of using partial_sum():
อัลกอริทึมทั้งสองต่อไปนี้จะช่วยให้คุณสามารถแปลงค่าญาติลำดับที่เป็นลำดับของ
ค่า และ รองในทางกลับกัน
แปลงค่าสัมพัทธ์เป็นค่า
OutputIterator
partial_sum (InputIterator sourceBeg, InputIterator sourceEnd,
OutputIterator destBeg)
OutputIterator
partial_sum (InputIterator sourceBeg, InputIterator sourceEnd,
OutputIterator destBeg BinaryFunc op)
•แบบแรกคำนวณผลรวมสำหรับแต่ละองค์ประกอบได้บางส่วน [sourceBeg,
sourceEnd) และเขียนผลลัพธ์แต่ละช่วงปลายเริ่มต้น ด้วย destBeg
•แบบที่สองเรียก op สำหรับแต่ละองค์ประกอบได้ [sourceBeg,sourceEnd) รวม
ค่าก่อนหน้านี้และการเขียนแต่ละผลช่วงปลายเริ่มต้น ด้วย destBeg
•ดังนี้ ค่า
a1 a2 a3...
จะคำนวณทั้ง
a1, a1 a2, a1 a2 a3,...
หรือ
a1, a1 op a2, a1 op a2 op a3,...
ตามลำดับ
•รูปแบบรับตำแหน่งหลังจากเขียนค่าสุดท้ายในช่วงปลาย (องค์ประกอบแรก
ที่ถูกเขียนทับ) .
•แบบแรกจะเท่ากับแปลงของลำดับของค่าที่สัมพันธ์กันเป็นลำดับ
ค่าสัมบูรณ์ ในเรื่องนี้ partial_sum() อัลกอริทึมเป็นส่วนเติมเต็มของ algorithm
adjacent_difference() (ดูหน้า 628) ได้
•ช่วงต้นทางและปลายทางอาจจะเหมือนได้
•ผู้เรียกต้องแน่ใจว่า ช่วงปลายมีขนาดใหญ่เพียงพอ หรือที่แทรกใช้ iterators ได้
• op ควรปรับเปลี่ยนการส่งผ่านอาร์กิวเมนต์ด้วย
•ความซับซ้อน: เส้น (numElems เรียกตัวหรือ op() ตามลำดับ) ได้
โปรแกรมต่อไปนี้แสดงให้เห็นถึงตัวอย่างของการใช้ partial_sum():
การแปล กรุณารอสักครู่..

ต่อไปนี้สองขั้นตอนวิธีการช่วยให้คุณสามารถแปลงลำดับของค่าความสัมพันธ์เป็นลำดับของ
ค่าแน่นอนและในทางกลับกัน
การแปลงค่าเป็นญาติค่าสัมบูรณ์
OutputIterator
partial_sum (InputIterator sourceBeg, InputIterator sourceEnd,
OutputIterator destBeg)
OutputIterator
partial_sum (InputIterator sourceBeg, InputIterator sourceEnd ,
OutputIterator destBeg, BinaryFunc op)
•รูปแบบแรกจะคำนวณผลรวมบางส่วนสำหรับแต่ละองค์ประกอบอยู่ในช่วงที่มา [sourceBeg,
sourceEnd) และเขียนแต่ละผลไปยังช่วงที่เริ่มต้นด้วย destBeg
•รูปแบบที่สองเรียก op สำหรับแต่ละองค์ประกอบใน ช่วงที่มา [sourceBeg, sourceEnd) รวม
กับค่านิยมก่อนหน้านี้ทั้งหมดและเขียนแต่ละผลไปยังช่วงที่เริ่มต้นด้วย destBeg
•ดังนั้นสำหรับค่า
a1 a2 a3 ...
พวกเขาคำนวณทั้ง
a1, a2 a1 +, a1 + a2 + a3 , ...
หรือ
a1, a2 a1 op, a1 a2 a3 op op, ...
ตามลำดับ
•รูปแบบที่ทั้งสองกลับตำแหน่งหลังจากที่ค่าเขียนสุดท้ายในช่วงปลายทาง (องค์ประกอบแรก
ที่ไม่ได้ถูกเขียนทับ)
•ครั้งแรก รูปแบบเทียบเท่ากับการเปลี่ยนแปลงของลำดับของค่าความสัมพันธ์เป็นลำดับ
ของค่าแน่นอน ในเรื่องนี้ขั้นตอนวิธีการ partial_sum () เป็นส่วนประกอบของขั้นตอนวิธี
adjacent_difference () (ดูหน้า 628)
•ต้นทางและปลายทางช่วงอาจจะเหมือนกัน
•โทรต้องให้แน่ใจว่าช่วงปลายทางมีขนาดใหญ่พอหรือว่าใส่ iterators ถูกนำมาใช้ .
•สหกรณ์ไม่ควรปรับเปลี่ยนการขัดแย้งที่ผ่าน
•ซับซ้อน: เชิงเส้น (สาย numElems ของผู้ประกอบการ + หรือสหกรณ์ () ตามลำดับ)
โปรแกรมต่อไปนี้แสดงให้เห็นถึงตัวอย่างบางส่วนของการใช้ partial_sum ():
การแปล กรุณารอสักครู่..

ต่อไปนี้สองขั้นตอนวิธีที่ช่วยให้คุณแปลงลำดับของค่าสัมพัทธ์เป็นลำดับ
ค่าสัมบูรณ์ และในทางกลับกัน การแปลงค่าสัมพัทธ์ในแน่นอนค่า
outputiterator
partial_sum ( inputiterator sourcebeg inputiterator sourceend
, ,
outputiterator destbeg ) outputiterator partial_sum ( inputiterator sourcebeg inputiterator sourceend outputiterator destbeg
, , ,binaryfunc op )
- รูปแบบแรกจะคำนวณผลรวมบางส่วนของแต่ละธาตุในช่วง sourcebeg
[ แหล่งที่มา , sourceend ) และเขียนแต่ละผลไปยังปลายทางช่วงเริ่มต้นด้วย destbeg .
- แบบฟอร์มที่สองสาย OP สำหรับแต่ละองค์ประกอบในช่วง [ sourcebeg แหล่งรวม sourceend ) ,
กับค่าก่อนหน้าทั้งหมด เขียน แต่ละผลไปยังปลายทางช่วงเริ่มต้นด้วย destbeg .
- ปานสำหรับค่า A1 A2 A3
. . . . . . . เขาคำนวณให้
A1 , A1 A2 A1 A2 A3 , . . . . . . .
หรือ A1 , A1 และ A2 A1 A2 A3 OP OP . . .
-
ตามลำดับ ทั้งรูปแบบคืนตำแหน่ง หลังจากล่าสุดเขียนค่าในช่วงปลายทาง ( ก่อนองค์ประกอบ
ว่า ไม่เขียนทับ )
- รูปแรก เทียบเท่ากับ การเปลี่ยนแปลงของลำดับของค่าสัมพัทธ์เป็นลำดับ
ค่าสัมบูรณ์ ในการนี้ขั้นตอนวิธี partial_sum() เป็นส่วนเติมเต็มของ adjacent_difference() ขั้นตอนวิธี
( เห็นหน้าแล้ว )
- แหล่งที่มาและปลายทางช่วงอาจจะเหมือน .
- โทรต้องมั่นใจว่า ช่วงปลายมีขนาดใหญ่พอ หรือใส่ iterators ใช้ .
- op ไม่ควรปรับเปลี่ยนผ่านอาร์กิวเมนต์ .
- ความซับซ้อนเชิงเส้น ( numelems โทร : ของผู้ประกอบการ หรือ op()
ตามลำดับ )รายการต่อไปนี้แสดงให้เห็นตัวอย่างของการใช้ partial_sum() :
การแปล กรุณารอสักครู่..
