adjacent_difference [C++ Reference]
Keywords: stl,algorithm,adjacent_difference
Date: 2009-10-09T00:34:12-0700

[[adjacent_difference]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## adjacent_difference

Syntax:

        #include <numeric>
        output_iterator adjacent_difference( input_iterator start, input_iterator end, output_iterator result );
        output_iterator adjacent_difference( input_iterator start, input_iterator end, output_iterator result, BinaryFunction f );

The adjacent_difference() function calculates the differences between adjacent elements in the range [start,end) and stores the result starting at result. (Specifically, the element at start will be copied to result; and then the difference between the element at start + i and start + (i-1) will be stored at result + i.)

If a binary function f is given, it is used instead of the - operator to compute the differences. adjacent_difference() runs in linear time.

Related Topics: accumulate, count, inner_product, partial_sum

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •