二叉树:在孩子兄弟链表表示的树中求叶子节点的个数

typedef struct CSNode {
  int val;
  CSNode *firstchild, *nextsibling;
} CSNode, *CSTree;

int dfs(CSTree *root) {
  if (!root) return 0;
  else if (!root->firstchild) return 1;
  else {
    int left  =  dfs(root->firstchild);
    int right = dfs(root->nextsibling);
    return left + right;
  }
}
发布了235 篇原创文章 · 获赞 51 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/ASJBFJSB/article/details/103225581