I have a question regarding the creation and manipulation of multi-dimensional dynamic arrays. I specifically don't want to use vectors - i'm comfortable using them, but i have good reasons for doing what i'm doing......
Anyway - i'm creating an m X n array (NumberOfPoints X choose_k), with the following bit of code.
1 2 3 4 5 6 7 8 9
int **nnArray = NULL;
nnArray = newint*[NumberOfPoints];
for(int i = 0; i < mNumberOfPoints; i++) // this creates the m X n array
nnArray[i] = newint[choose_k];
delete [] nnArray; // make sure to delete when finished with it......
My question is - what are the dimensions of the array, if we say NumberOfPoints = 100, and choose_k = 5
Do we have a 100 X 5 array, or a 5 X 100 array? Does it make a difference (i would have thought so, yes!!)
So, if i wanted to access the element relating to NumberOfPoints = 60, and choose_k = 3, what would my syntax be?
1 2
nnArray [60][3] = something; // OR
nnArray [3][60] = something; // This one?
int *nnArray = newint [ NumberOfPoints*choose_k ];
nnArray [ x + y*choose_k ]; // access element x, y as NumberOfPoints x choose_k array
nnArray [ x + y*NumberOfPoints ]; // access element x, y as choose_k x NumberOfPoints array
delete[] nnArray; // now this will free the whole memory used by nnArray