开发者

Calling function x from within function y and vice versa in the same program

开发者 https://www.devze.com 2023-03-17 23:30 出处:网络
int right(int n) { if(n>0) { n--; top_lim ++; cout<<\"R\"; right_lim--; if(right_lim < size) return(right(n-1));
int right(int n)
{
        if(n>0)
        {
            n--;
            top_lim ++;
            cout<<"R";
            right_lim--;
            if(right_lim < size)
            return(right(n-1));
            i开发者_开发问答f(top_lim>0)
-->            return(up(n - 1));
        }
        else
        {
            return 0;
        }

}
int up(int n)
{
if(n>1)
        {
            n--;
            top_lim --;
            cout<<"U";
            if(right_lim < size)
            return(right(n-1));
            if(top_lim > 0 )
            return(up(n-1));
        }
        else
        {
            return 0;
        }
}

error: [17] 'up' was not declared in this scope|--> indicates error in code ..

Description of problem:

The problem is to find all the possible number of paths in a n*n grid in the portion below the diagonal starting from (0,0) to (n,n) I basically call the right function first in the main function and then it should print me all paths.

Is there a workaround for this?


Add a forward declaration at the top of your code:

int up(int);

(Make sure to compile that code with full optimizations! :-) )

0

精彩评论

暂无评论...
验证码 换一张
取 消