|
-
Nov 12th, 2005, 06:00 PM
#1
Thread Starter
Frenzied Member
Putting an array inside of an array.
Not sure if this is the appropriate forum, but it sounds like something a graphics programmer might have had to deal with before.
Let's say I have a 2D array of boolean, representing the surface of a monochrome screen. Let's say I have another 2D Array, representing an object to place in that screen, and want to put it in a specific place inside the first array. i.e,
00000000
00000000
00000000
00000000
00000000
00000000
is my first array
and
11
11
is my second.
What would be a good way (in psuedocode) to do something like this
InsertArray(4,3)
That would result in the original array looking like
00000000
00000000
00011000
00011000
00000000
00000000
Any suggestions? Obviously the arrays are much bigger, but the idea should be the same regardless..
Bill
-
Nov 12th, 2005, 06:22 PM
#2
Thread Starter
Frenzied Member
Re: Putting an array inside of an array.
I found a way to do it if I know beforehand the size of the array being placed into the first array. Is there a way to get the dimensions of a 2D array? For example, if I have a 4x4 array, and call Array.Length, I will get 16. Since it won't always be a square, is there a way to find out how the 2D array is structured?
Bill
-
Nov 12th, 2005, 08:02 PM
#3
Fanatic Member
Re: Putting an array inside of an array.
In what language? If you're talking vb6, you would get the first two dimensions using ubound(array,1) and ubound(array,2).
-
Nov 12th, 2005, 08:57 PM
#4
Thread Starter
Frenzied Member
Re: Putting an array inside of an array.
Should have specified... This is C#, but There should be an equivalent to ubound there somewhere.. Thanks.
Bill
-
Nov 12th, 2005, 09:39 PM
#5
Re: Putting an array inside of an array.
.NET uses Upperbound and LowerBound I think. Should be something like:
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Nov 21st, 2005, 09:45 AM
#6
Re: Putting an array inside of an array.
Code:
myArray.GetUpperBound(0); // first dimension
myArray.GetUpperBound(1); // second dimension
-
Nov 25th, 2005, 05:53 PM
#7
Re: Putting an array inside of an array.
So what are you doing?
If you have the main array (mainA() and the new array newA()), and you have a function Insert( left,top,newA()), then you could:
Loop through dimension 0
Loop through dimension 1
mainA(top plus outer loop, left plus inner loop) = newA(outer loop, inner loop)
That is roughly what could be done. Of course, you would only need to loop through a range defined by top+size of newA() dimension 0, and left+ size of newA() dimension 1.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|