Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

C++: Fusionner deux conteneurs de type différent

 list, list, map, iterator, set
{filelink=15242}

#include <iostream>
#include
<list>
#include <set>
#include
<map>
#include <string>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;
 
int tab1[] = { 2, 3, 4, 6, 8 };
int tab2[] = { 1, 3, 5 };
int main()
{
    list<int> conteneur1(tab1, tab1+5);
    set<int> conteneur2(tab2, tab2+3);
    ostream_iterator< int > output( cout, " " );
cout<<"Conteneur1: ";
	copy(conteneur1.begin(), conteneur1.end(), output);
    cout<<endl;
cout<<"Conteneur2: ";
	copy(conteneur2.begin(), conteneur2.end(), output);
    cout<<endl;
 
	// Afficher le résultat de la fusion
    cout << "Fusion: ";
    merge (conteneur1.begin(), conteneur1.end(),
           conteneur2.begin(), conteneur2.end(),
           output);
    cout << endl;
 
	return 0;
}

No comments yet.

Leave a Comment