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
|
#include <iostream>
#include <algorithm>
int main()
{
const int N1 = 5, N2 = 7, NBIG = 100 ;
static_assert( NBIG >= (N1+N2), "target array is too small" ) ;
const int first[N1] = { 20, 1, 22, 3, 24 } ;
const int second[N2] = { 65, 6, 57, 8, 49, 10, 31 } ;
{
int big[NBIG] = {} ;
// http://en.cppreference.com/w/cpp/algorithm/copy
const auto end = std::copy( second, second+N2, std::copy( first, first+N1, big ) ) ;
// http://en.cppreference.com/w/cpp/algorithm/sort
std::sort( big, end ) ;
for( auto ptr = big ; ptr != end ; ++ptr ) std::cout << *ptr << ' ' ;
std::cout << '\n' ;
}
{
int big[NBIG] = {} ;
// copy one by one
auto end = std::copy( first, first+N1, big ) ;
end = std::copy( second, second+N2, end ) ;
std::sort( big, end ) ;
for( auto ptr = big ; ptr != end ; ++ptr ) std::cout << *ptr << ' ' ;
std::cout << '\n' ;
}
}
|