1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <list>
#include <map>
#include <iterator>
#include <algorithm>
using namespace std;
int main(int argc, char **argv)
{
// notre liste d'entiers
typedef list<int> ListInt;
// notre map entier/liste
typedef map<int,ListInt> IntListMap;
ListInt list1, list2;
IntListMap ilm;
// remplissage des listes
list1.push_back(1);
list1.push_back(2);
list2.push_back(3);
list2.push_back(4);
// remplissage du map
ilm[1] = list1;
ilm[2] = list2;
cout << "list1 : ";
copy(list1.begin(), list1.end(), ostream_iterator<int>(cout," "));
cout << endl;
cout << "list2 : ";
list2.push_back(5);
copy(list2.begin(), list2.end(), ostream_iterator<int>(cout," "));
cout << endl;
cout << "ilm[2] pour montrer que, dans ce cas ilm[2] est différent de list2: ";
ListInt list3 = ilm[2];
copy(list3.begin(), list3.end(), ostream_iterator<int>(cout," "));
cout << endl;
cout << "le map : " << endl;
IntListMap::iterator pos;
for ( pos = ilm.begin(); pos != ilm.end(); ++pos)
{
ListInt l = pos->second ;
cout << "[" << pos->first << "] = " ;
copy(l.begin(), l.end(), ostream_iterator<int>(cout," "));
cout << endl;
}
} |
Partager