PROGRAM :
Code:
#include <iostream>
#include <algorithm>
using std::cout;
using std::endl;
int main()
{
int s1[ 5 ] = { 1, 3, 5, 7, 9 };
int s2[ 5 ] = { 2, 4, 5, 7, 9 };
std::vector< int > w1( s1, s1 + 5 );
std::vector< int > w2( s2, s2 + 5 );
std::iostream_iterator< int > output( cout, " " );
std::copy( w1.begin(), w1.end(), output );
cout << "\n\n";
std::copy( w2.begin(), w2.end(), output );
std::vector< int > rslts2( w1.size() + w2.size() );
std::merge( w1.begin(), w1.end(), w2.begin(), w2.end(), rslts2.begin() );
cout << "\n\n After merge of w1 and w2 rslts2 contains:\n";
std::copy( rslts2.begin(), rslts2.end(), output );
cout << endl;
return 0;
}
OUTPUT :
Code:
1 3 5 7 9
2 4 5 7 9
After merge of w1 and w2 rslts2 contains:
1 2 3 4 5 5 7 7 9 9
Bookmarks