Home > Back-end >  The parameters of the function recursive calls
The parameters of the function recursive calls

Time:09-23

Void Weight_BN (BiTree t, int deep) the width of the binary tree////o int CC [20]={0}; Int Flag=1; CC [], the Flag for the global variable
{
If (t)
{
Printf (" % c \ t, t - & gt; The data);
CC [deep] + +;
Printf (" CC (deep) : \ n \ t % d ", CC (deep));
If (FlagFlag=CC (deep);
Weight_BN (t - & gt; Lchild, + + deep);
Weight_BN (t - & gt; Rchild, + + deep);
}
}

Void Weight_BN (BiTree t, int deep) the width of the binary tree////o int CC [20]={0}; Int Flag=1; CC [], the Flag for the global variable
{
If (t)
{
Printf (" % c \ t, t - & gt; The data);
CC [deep] + +;
Printf (" CC (deep) : \ n \ t % d ", CC (deep));
If (FlagFlag=CC (deep);
Weight_BN (t - & gt; Lchild, deep + 1);
Weight_BN (t - & gt; Rchild, deep + 1);
}
}

This is a recursive binary tree width problem, I just wonder why + + + 1 out the results of the deep and deep, deep + 1 is right, + + deep is wrong,

CodePudding user response:

Su Hu look here is no problem, you can output value of the deep see the entrance of the function, to see what is the difference between two kinds of situations

CodePudding user response:

+ + deep, deep change itself, + 1, deep deep itself doesn't change,

CodePudding user response:

Weight_BN (t - & gt; Lchild, deep + 1);//if it is + + deep here
Weight_BN (t - & gt; Rchild, deep + 1);//deep is here is a function parameter plus one, is not traverse the same layer data, so wrong,

CodePudding user response:

reference 3 floor truth is right or wrong response:
Weight_BN (t - & gt; Lchild, deep + 1);//if it is + + deep here
Weight_BN (t - & gt; Rchild, deep + 1);//deep is here is a function parameter on one, that is not traverse the same layer data, so the error,

+ +, however, deep and useless to the pointer, recursive system internal stack, isn't it, if not through Pointers, + + deep back from the next layer, deep values should not be coming back, traverse the same layer, such as the first layer is A, deep is 1, then the recursive call to the next layer of B, deep from 1-6, deep is 2, suppose the next layer is the C, B + + deep should not be in 3, and then corresponding CC/deep value should also change, if the recursive back, deep isn't A pointer, is that A 2 B corresponding deep shouldn't, but I tested the if not, say, I feel I lack of knowledge is good,

CodePudding user response:

reference 1/f, 5250 response:
Su Hu look here is no problem, you can output the value of the deep see the entrance of the function, to see what is the difference between two cases



reference 3 floor truth is right or wrong response:
Weight_BN (t - & gt; Lchild, deep + 1);//if it is + + deep here
Weight_BN (t - & gt; Rchild, deep + 1);//deep is here is a function parameter on one, that is not traverse the same layer data, so the error,

like the + + k, is ok, but not to the trees

CodePudding user response:

Because only a ma,

CodePudding user response:

If still not understand?
That for a specific number:
Such as: deep=1;
Weight_BN (t - & gt; Lchild, deep + 1);
Weight_BN (t - & gt; Rchild, deep + 1);
The equivalent of
Weight_BN (t - & gt; Lchild, 2);
Weight_BN (t - & gt; Rchild, 2);
============================
Weight_BN (t - & gt; Lchild, + + deep);
Weight_BN (t - & gt; Rchild, + + deep);
The equivalent of
Weight_BN (t - & gt; Lchild, 2);
Weight_BN (t - & gt; Rchild, 3);

CodePudding user response:

refer to 7th floor truth is right or wrong response:
if you still not understand?
That for a specific number:
Such as: deep=1;
Weight_BN (t - & gt; Lchild, deep + 1);
Weight_BN (t - & gt; Rchild, deep + 1);
The equivalent of
Weight_BN (t - & gt; Lchild, 2);
Weight_BN (t - & gt; Rchild, 2);
============================
Weight_BN (t - & gt; Lchild, + + deep);
Weight_BN (t - & gt; Rchild, + + deep);
The equivalent of
Weight_BN (t - & gt; Lchild, 2);
Weight_BN (t - & gt; Rchild, 3);

Have a little understand, that if the lower nested calls again, could it be that
Weight_BN (t - & gt; Lchild, + + deep);
Weight_BN (t - & gt; Rchild, + + deep);
Weight_BN (t - & gt; Lchild, 2);
{
Weight_BN (t - & gt; Lchild, 4);
Weight_BN (t - & gt; Rchild, 5)
}
Weight_BN (t - & gt; Rchild, 3)
{
Weight_BN (t - & gt; Lchild, 6);
Weight_BN (t - & gt; Rchild, 7)
} to be such a

CodePudding user response:

Computer science, at best, a more rigorous discipline, said it is fatal in bad, almost no, you're more than a semicolon, a letter, a bracket, it will think you are wrong,
So, can't understand such nuances, my opinion is that it is best not to into the line, you don't fit for this industry,

CodePudding user response:

references 9/f, the truth is right or wrong response:
in computer science, at best, a more rigorous discipline, said it is fatal in bad, almost no, you're more than a semicolon, a letter, a bracket, it will think you are wrong,
So, can't understand such nuances, my opinion is that it is best not to into the line, you don't fit for this industry,

Educated, thanks to criticism
  • Related