Link to home
Start Free TrialLog in
Avatar of gothic130
gothic130

asked on

recursion

hi, when you have a recursive function that works like this:

call 1           i=1
call 2              i=2
call 3                 i=3
call 4                 3
call 5              2
call 6          1

I can get the value of i until the 3, but then it began to decrese, how could I avoid that? because the next value I need is i=4.

this is my function:

public void DFS(verticeGrapho tmp, int i, int j, int n, int[,] ma, int g)
{
            tmp.info = i;
            i++;
            for (int k = g; k <= n; k++)
            {
                if (ma[j, k] == 1 && tmp.info == 0)
                {
                    DFS(tmp, i, g, n, ma, g);
                }
                    tmp = tmp.next; g++;
            }
}

Hope you understand my question!!!

Thanks!!!

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of badbearontour
badbearontour

HI,

I'm not sure we can help without seeing the code for the verticeGrapho object and more explanation about the variables used, but something in the call must make the tmp.info member = 0. otherwise you would never come out of the recursive loop. what does tmp.next do?

BB