Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

C++: Vérifier si deux collections sont égaux

 list, list, deque
{filelink=15153}

#include <vector>
#include
<list>
#include <deque>
#include <algorithm>
#include <iterator>
#include <iostream>
using namespace std;
 
int main()
{
	int tab[ ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	int tab2[ ] = { 2, 4, 6, 8, 10, 12, 14, 16, 18 };
    vector<int> coll1(tab, tab+9);
    list<int> coll2(tab2, tab2+9);
    deque<int> coll3;
   ostream_iterator< int > output( cout, " " );
 
	for(int x=0;x<9;x++)
		 coll3.push_back(tab[x]*2);
 
   /* Affichage du contenu */
   cout<<"Contenu du Coll1: ";
   copy( coll1.begin(), coll1.end(), output );
   cout<<endl;
   cout<<"Contenu du Coll2: ";
   copy( coll2.begin(), coll2.end(), output );
   cout<<endl;
   cout<<"Contenu du Coll3: ";
   copy( coll3.begin(), coll3.end(), output );
   cout<<endl;
 
   /* Comparaison des collections */
	cout<<(equal(coll1.begin(), coll1.end(),
		coll2.begin())?"coll1==coll2":"coll1 !=coll2") ;
 
	cout<<endl;
 
	cout<<(equal(coll2.begin(), coll2.end(),
		coll3.begin())?"coll2==coll3":"coll2 !=coll3") ;
	cout<<endl;
 
	return 0;
 
}
 
/*
Contenu du Coll1: 1 2 3 4 5 6 7 8 9
Contenu du Coll2: 2 4 6 8 10 12 14 16 18
Contenu du Coll3: 2 4 6 8 10 12 14 16 18
coll1 !=coll2
coll2==coll3
Press any key to continue
 
 */

No comments yet.

Leave a Comment