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,