第一题:
int LeafCount(BiTree T) { if (T == NULL) { return 0; } if (T->lchild == NULL && T->rchild == NULL) { return 1; } return LeafCount(T->lchild) + LeafCount(T->rchild); }
第二题:
int Depth(BiTree T) { if (T == NULL) { return 0; } int leftDepth = Depth(T->lchild); int rightDepth = Depth(T->rchild); return (leftDepth > rightDepth ? leftDepth : rightDepth) + 1; }
推荐阅读:
数字逻辑电路74LS161四位二进制同步计数器剖析数电期末复习C++ PTA答案C plus plus PTA 第一章C plus plus PTA 第二章实验五读懂中国茶--第四章作业离散数学6.1-6.2 图的基本概念参考答案
提交评论