Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exemple d’utilisation de ‘min_element()’ avec des critères

 deque, iterator
{filelink=15171}

#include <iostream>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
 
bool is_abs (int elem1, int elem2)
{
    return abs(elem1) < abs(elem2);
}
 
int main()
{
    deque<int> coll;
    ostream_iterator<int> output(cout, " ");
    for(int x=-3; x<=5; x++)
		coll.push_back(x);
 
     cout<<"Le contenu du deque: ";
	copy(coll.begin(), coll.end(), output);
	cout<<endl;
 
    cout << "Min des valeurs absolues: "
         << *min_element(coll.begin(),coll.end(),
                         is_abs)
         << endl;
return 0;
}

No comments yet.

Leave a Comment