Answer the question
In order to leave comments, you need to log in
How to combine three one-dimensional arrays into one?
How to combine three one-dimensional arrays into one?
Answer the question
In order to leave comments, you need to log in
Create an array with enough elements and copy the three arrays to be combined into it :)
PS I advise you to use std::vector.
std::vector<int> dest = {1,2,3};
std::vector<int> src = {4,5,6};
std::vector<int> src2 = {6,7,8};
dest.insert( dest.end(), src.begin(), src.end() );
dest.insert( dest.end(), src2.begin(), src2.end() );
I would dump them one by one into one array or vector
www.cplusplus.com/reference/algorithm/copy
and then call the function
twice www.cplusplus.com/reference/algorithm/inplace_merge
If the arrays are length 10, 15 and 20 then …
• First time - std::inplace_merge(v.begin(), v.begin() + 10, v.begin() + 10 + 15);
• Second time - std::inplace_merge(v.begin(), v.begin() + 10 + 15, v.begin() + 10 + 15 + 20);
STL will help you
const std::vector<int>
first{ 1, 2, 3 }, second{ 4, 5, 6 }, third{ 7, 8, 9 };
std::vector<int> result=first;
std::copy(second.cbegin(), second.cend(), std::back_inserter(result));
std::copy(third.cbegin(), third.cend(), std::back_inserter(result));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question