Dynamic two dimensional Arrays
Author |
Message |
copthesaint

|
Posted: Mon Apr 04, 2011 10:54 am Post subject: Dynamic two dimensional Arrays |
|
|
So I know what increasing the bound of a dynamic array, you want to create a temperary array with the larger bound and copy the previous array to it. eg.
Java: | int boundSize = 1;
int[] oldArray = new int [boundSize ];
oldArray [boundSize- 1] = 0;
boundSize = boundSize+ 1;
int[] newArray= new int[boundSize ];
System. arraycopy(oldArray, 0, newArray, 0, oldArray. length);
oldArray= newArray;
oldArray [boundSize- 1] = 1;
for (int i = 0; i < oldArray. length; i++ ){
System. out. println (oldArray [i ]);
} |
However I am just wondering how I would go about doing this with a [][] dimensional array. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Mon Apr 04, 2011 11:54 am Post subject: RE:Dynamic two dimensional Arrays |
|
|
Mostly in the same way. If you have int[][] arr; wouldn't arr[x] return an int[] type?
Also, the typical strategy for resizing arrays is to double their length (instead of doing +1), but that choice depends on the behaviour of your program. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
copthesaint

|
Posted: Mon Apr 04, 2011 4:03 pm Post subject: RE:Dynamic two dimensional Arrays |
|
|
Yep, I realized like 10 min after, when I ate something, That arr[x] would return an array... I kinda just face-palmed myself.. anyways thanks  |
|
|
|
|
 |
|
|