已知二叉树中的结点类型用BinTreeNode表示,被定义为:
struct BinTreeNode{
char data; BinTreeNode *lChild, *rChild;};
其中:data为结点值域;lChild和rChild分别为指向左、右子女结点的指针域。
根据下面函数声明编写出求一棵二叉树非叶子节点数目的算法。
struct BinTreeNode{
char data; BinTreeNode *lChild, *rChild;};
其中:data为结点值域;lChild和rChild分别为指向左、右子女结点的指针域。
根据下面函数声明编写出求一棵二叉树非叶子节点数目的算法。
int sum(BinTreeNode *node)
解:
int sum(BinTreeNode *node)
{
if (node==null ¦ ¦ (node-> lChild==null && node-> rChild==null)) return 0;
else return sum(node-> lChild)+sum(node-> rChild)+1;
}