Referring 2D sub array in C++

Jan 29, 2010 at 3:35pm
Hi all,

I am trying to create a recursive solution to a problem which takes a lower-triangular matrix (basically a 2D array in which all elements where column is greater than row is zero). I need to recursively pass smaller and smaller sub-array to the function till I reach an array containing a single element. Also, I do not know the size of array in advance so I dynamically allocated memory with following code:

1
2
3
4
int **a;
a = new int* [l];
for (int i=0;i<l;i++)
	*(a+i) = new int[l];

Now I need to recursively pass the smaller sections of the subarray, for example if the array is:
3 0 0 0
7 4 0 0
2 4 6 0
8 5 9 3

Then I need to recurse twice, once on the sub-array:
7 4 0
2 4 6
8 5 9

Then on:
4 0 0
4 6 0
5 9 3

How can I pass the reference to a sub-array?
Jan 29, 2010 at 4:43pm
While the first one is easily possible, the second one requires you to build a completely
new 2D array that is 3x3.
Topic archived. No new replies allowed.