小编srb*_*rbh的帖子

该函数如何计算树中的节点数?

用于计算树中节点数的函数.

int count(node *t)
{    
    int i;  
    if (t == NULL)         
        return(0);  
    i = 1 + count(t->left) + count(t->right); // recursion occurs address of left node is passed and 
    return(i);                                // continue to pass until whole left node
}                                             // is traversed and the value of t is
                                              // NULL and 0 is returned same for right node counting
                                              // i = 1 + 0 + 0 = 1
Run Code Online (Sandbox Code Playgroud)

如何计算节点数?

c tree recursion

2
推荐指数
1
解决办法
7340
查看次数

标签 统计

c ×1

recursion ×1

tree ×1