主题:这两编写题有错吗?大虾指教!~```
1、编写一算法计算二叉树中的结点总数?
int CountNode(BinTree *root)
{
int num1,num2;
if(root==Null) return(0);
else if(root->lchild==Null&&rooot->rchild==Null)
return(1);
else
{
num1=CountNode(root->lchild);
num2=CountNode(root->rchild);
return(num1+num2+1);
}
}
2、编写一算法计算二叉树中叶子结点的个数?
int CountLeafs(BinTree *root)
{
int num1,num2;
if(root==Null) return(0);
else if(root->lchild==Null&&root->rchild==Null)
return(1);
else
{
num1=CountLeafs(root->lchild);
num2=CountLeafs(root->rchild);
return(num1+num2);
}
}
[em1][em1][em1]
int CountNode(BinTree *root)
{
int num1,num2;
if(root==Null) return(0);
else if(root->lchild==Null&&rooot->rchild==Null)
return(1);
else
{
num1=CountNode(root->lchild);
num2=CountNode(root->rchild);
return(num1+num2+1);
}
}
2、编写一算法计算二叉树中叶子结点的个数?
int CountLeafs(BinTree *root)
{
int num1,num2;
if(root==Null) return(0);
else if(root->lchild==Null&&root->rchild==Null)
return(1);
else
{
num1=CountLeafs(root->lchild);
num2=CountLeafs(root->rchild);
return(num1+num2);
}
}
[em1][em1][em1]