Mega Code Archive

 
Categories / C++ / Algorithm
 

Adjacent_difference( ) returns a new sequence in which each element is the difference between adjacent elements in the original

#include <iostream> #include <vector> #include <numeric> using namespace std;     int main() {   vector<int> v(10), r(10);   int i;       for(i=0; i<10; i++) {     v[i] = i*2;     cout << v[i] << endl;   }         adjacent_difference(v.begin(), v.end(), r.begin());       for(i=0; i<10; i++)     cout << r[i] << endl;       return 0; }