Looking to merge two different 2D arrays of different row sizes into one long array:
int 2dArray1[][] = {
{1, 2, 3},
{4, 5, 6}};
int 2dArray2[][] = {
{10, 20},
{30, 40}};
int 1dLongArray[10];
This is where I need help in order to have the values of 1dLongarray be arranged as follows:
1, 2, 3, 10, 20, 4, 5, 6, 30, 40
How would I achieve this? Thanks in advance.
1 Answer 1
Consider using loops of length specific to the desired number of transactions. For example, using this pseudo code create a sketch which follows this pattern:
initialize i to zero
loop 2 times for each row using the variable x
loop 3 times for each element in first array using the variable y
long array [i] = first array[x][y]
increment i
loop 2 times for each element in a second array using the variable z
long array [i] = second array[x][z]
increment i
answered Nov 29, 2020 at 23:36
-
Being a brand new account I can't upvote your comment yet, so I'm leaving this comment to thank you!Hitachii– Hitachii2020年11月30日 01:42:33 +00:00Commented Nov 30, 2020 at 1:42
-
If you can derive a working solution from this answer, you should be able to accept this answer as a solution to your question.st2000– st20002020年11月30日 01:49:32 +00:00Commented Nov 30, 2020 at 1:49
-
Thanks @Hitachii for making the answer as correct. If the answer works great! If not, please leave a comment and I'll edit the answer to improve it.st2000– st20002020年11月30日 14:54:18 +00:00Commented Nov 30, 2020 at 14:54
-
Sure. If someone were to plug the guideline for the formula that you posted, into the problem that I posted, for "long array [i] = first array [y] [x]" and "long array [i] = second array [z][x], they would have to switch the placement of x and z/y in their respective line to look like "long array [i] = first array [x][y]" to follow the original sequence of the array. Do I post my working code? This shows how green I am to this platform.Hitachii– Hitachii2020年11月30日 21:10:11 +00:00Commented Nov 30, 2020 at 21:10
-
You are correct. The 1st argument is the row and the second is the column. I'll change my answer.st2000– st20002020年12月01日 05:37:59 +00:00Commented Dec 1, 2020 at 5:37
write down first three numbers
... i mean baby steps, likelook at array1, row1, position1. copy content to first empty position at destination