Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Trier le contenu d’une collection avec l’algorithme ‘partial_sort()’

 vecteur, iterator
{filelink=15212}

 
#include <iostream>
#include <vector>
#include <vector>
#include <algorithm>
#include <functional>
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()
{
    vector<int> vec;
    ostream_iterator<int> output(cout," ");
    inserer_elements(vec,12,18);
    inserer_elements(vec, 8, 21);
 
	cout<<"Le contenu du vector: ";
    copy(vec.begin(), vec.end(), output);
    cout<<endl;
 
    //Trier le contenu du vecteur
    partial_sort (vec.begin(), vec.end(), vec.end());
 
	cout<<"Le contenu du vector trié: ";
    copy(vec.begin(), vec.end(), output);
    cout<<endl;
 
	return 0;
}

No comments yet.

Leave a Comment