Calculer les differences successives entres les éléments d’une collection à l’aide de la fonction ‘adjacent_difference’

Author:

 calcul, deque, iterator
{filelink=15270}

#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int main()
{
   deque deq;
   ostream_iterator output( cout, " " );

    for (int i=1; i<=10; ++i)
	{
        deq.insert(deq.end(),i);
    }

   cout << "Contenu du deque: n";
   copy( deq.begin(), deq.end(), output );

    cout << endl;
   // Comparer et afficher les résultat

   adjacent_difference (deq.begin(), deq.end(),         // source
                        ostream_iterator(cout," ")); // dest.
   cout << endl;

return 0;
}

/*
Contenu du deque:
1 2 3 4 5 6 7 8 9 10
1 1 1 1 1 1 1 1 1 1

 */        

Leave a Reply

Your email address will not be published. Required fields are marked *