统计二叉树中度为1的结点个数。
template
int BinaryTree :: Degrees1 ( BinTreeNode * t ) const {
if ( t == NULL ) return 0;
if ( t->leftChild != NULL && t->rightChild == NULL ||
t->leftChild == NULL ...统计二叉树中度为1的结点个数。
template
int BinaryTree :: Degrees1 ( BinTreeNode * t ) const {
if ( t == NULL ) return 0;
if ( t->leftChild != NULL && t->rightChild == NULL ||
t->leftChild == NULL && t->rightChild != NULL ) return 1;//我非常不理解这里 既然都返回1了,那后面继续递归,如果还有度数为一的结点那怎么办呢,为什么没有设定一个count统计数目呢 这样子递归能实现么???
return Degrees1 ( t->leftChild, k ) + Degrees1 ( t->rightChild, k );
}展开 |
|