Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Trier les éléments d’un deque avec l’algorithme ‘sort()’

 deque, iterator
{filelink=15222}

#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
 
template <class T>
inline void inserer_elements (T& coll, int first, int last)
{
    for (int i=first; i<=last; ++i) {
        coll.insert(coll.end(),i);
    }
}
 
int main()
{
    deque<int> deq;
    ostream_iterator<int> output(cout," ");
 
    inserer_elements(deq,-9,-2);
    inserer_elements(deq,-22,-18);
    inserer_elements(deq,8,13);
 
    cout<<"Le contenu du deque: ";
    copy(deq.begin(), deq.end(), output);
    cout<<endl;
 
    // Trier les éléments
    sort (deq.begin(), deq.end());
 
    cout<<"Le contenu du deque après le tri: ";
    copy(deq.begin(), deq.end(), output);
    cout<<endl;
 
	return 0;
}

No comments yet.

Leave a Comment