hi frndz...

the problem is as follows:

i want to create a 2-d array. in every index in that matrix, i want to store an array of integers. moreover the array that i want to store at every index has to be dynamic because its size will keep on increasing.
so if suppose the matrix is a 4x4 matrix as follows.

0........ ......1.................. 2.....................3

0 array[n1] . array[n2] . array[n3] . array[n4]

1 array[b1] . array[b2] . array[b3] . array[b4]

2 array[c1] . array[c2] . array[c3] . array[c4]

3 array[d1] array[d2] . array[d3] . array[d4]
.
the size of these arrays at the indexes are to be decided dynamically at runtime, because the values of n1,n2.....,b1,b2,.......depend upon the size of previous array located at an index just before the current location.

i.e n2 is decided from n1....
n3 is decided from n2...
b2 is decided from b1...
in nutshell, all these arrays wil have a varying length that cannot be decided before or declared static beforehand.

also all the arrays inside the matrix are integer arrays.

how to declare such an array???

Edited by ayan2587: n/a

3
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by jonsca

Are you limited to using arrays or can you use vectors? You could use (brace for impact) vector<vector<vector<int> > >

hey...
i am limited to using arrays..
cannot use any STL here....

Are you limited to using arrays or can you use vectors? You could use (brace for impact) vector<vector<vector<int> > >

So do you know how to create a regular 1d array of size n, dynamically?

Edited by firstPerson: n/a

yes...
it goes like this..

int *arr=new int;

for 2-d array...

int *arr=new int*[row];
for(int i=0;i<row;i++)
arr=new int[col];

So do you know how to create a regular 1d array of size n, dynamically?

Then you know almost everything you need to know. All you need to know is how to link them. And the way to link them would be using a linked list.
Have you learned about them ?

Couldn't he set it up like this without the LL?

``````int *** matrix = new int**[3];
matrix[0] = new int*[3];
matrix[1] = new int*[3];
matrix[2] = new int*[3];
matrix[0][0] = new int[size];
matrix[0][1] = new int[n1_size];
matrix[0][2] = new int[n2_size];
....
matrix[2][2] = new int[yada];
where size, n1_size, n2_size come from values in the code``````

(Post 500)

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.