Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Trier les 5 premiers éléments d’une collection avec l’algorithme ‘partial_sort()’

 deque, iterator
{filelink=15210}

 
#include 
#include 
#include 
#include 
 
template 
inline void inserer_elements (T& coll, int first, int last)
{
    for (int i=first; i<=last; ++i) {
        coll.insert(coll.end(),i);
    }
}
 
using namespace std;
 
int main()
{
    deque deq;
    ostream_iterator output(cout," ");
    inserer_elements(deq,12,18);
    inserer_elements(deq, 8, 21);
 
	cout<<&quot;Le contenu du deque: &quot;;
    copy(deq.begin(), deq.end(), output);
    cout<<endl;
 
    //Trier les 5 premiers éléments du deque
    partial_sort (deq.begin(), deq.begin()+5, deq.end());
 
	cout<<&quot;Le contenu du deque trié partiellement: &quot;;
    copy(deq.begin(), deq.end(), output);
    cout<<endl;
 
	return 0;
}

No comments yet.

Leave a Comment