Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exemple d’utilisation de ‘merge()’ avec ‘ back_inserter()’

 iterator
{filelink=15241}

 
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
 
using namespace std;
 
int tab1[] = { 2, 3, 4, 6, 8 };
int tab2[] = { 1, 3, 5 };
int main( ) {
 
   vector<int> v1(tab1, tab1+5), v2(tab2, tab2+3), v3;
   ostream_iterator< int > output( cout, " " );
 
   merge(v1.begin( ), v1.end( ),
         v2.begin( ), v2.end( ),
         back_inserter<vector<int> >(v3));
 
   copy(v3.begin(), v3.end(), output);
 
return 0;
}
 
 /*
abcdef
 */

No comments yet.

Leave a Comment