Let's review the statistical depth this time:
May wish to review: the convenience of the sequence is to use the heap to obtain knowledge, in, out, first temp[in]=root, and then let the left and right sons in
Count the number of leaves: count++ when the left and right children reach NULL through recursion, and then search for other children when recursively
Now we look at the depth problem:
In-depth questions: http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/contestproblem/cid/2711/pid/2804
int searchdepth(struct node*root)
{
if(root==NULL)
return 0;
x=searchdepth(root->l);
y=searchdepth(root->r);
if(x>y)
return x+1;
else
return y+1;
}
How to build can see the previous article
What I want to say is: you can build the simplest binary tree abc, then the algorithm runs as follows (manual debug)
First root->then sp(root->l)->then continue to execute sp(root->l->l) in it, and find NULL, then x=0. Similarly, execute sp(root->r->r) y=0, execute if process y=1 (it doesn’t matter who adds one here anyway, at the end is x (recursive original function)=1), then sp (root->r) executes the same process