Dec 7, 2004 #1 RichieMac Programmer Joined Aug 18, 2004 Messages 61 Location GB Hi all, I have a two dimensional array that has to be made one dimensional. How would I go about adding each array on to the end of another. ie: anArray [3][255] into anArray [3*255].
Hi all, I have a two dimensional array that has to be made one dimensional. How would I go about adding each array on to the end of another. ie: anArray [3][255] into anArray [3*255].
Dec 7, 2004 #2 jstreich Programmer Joined Apr 20, 2002 Messages 1,067 Location US Code: int [][] x = new int[3][255]; int [] result = new int[3*255]; for(int i=0,3 > i; ++i) { for(int j = 0; 255 > j; += j) { //two ways result[i + 3 * j] = x[i][j]; //row major ordering //OR //result[j + 255 * i] = x[i][j]; //cullom major ordering } } Upvote 0 Downvote
Code: int [][] x = new int[3][255]; int [] result = new int[3*255]; for(int i=0,3 > i; ++i) { for(int j = 0; 255 > j; += j) { //two ways result[i + 3 * j] = x[i][j]; //row major ordering //OR //result[j + 255 * i] = x[i][j]; //cullom major ordering } }
Dec 7, 2004 Thread starter #3 RichieMac Programmer Joined Aug 18, 2004 Messages 61 Location GB Thanks mate. Upvote 0 Downvote
Dec 8, 2004 #4 jstreich Programmer Joined Apr 20, 2002 Messages 1,067 Location US n/p. Upvote 0 Downvote