中序遍历求二叉树中非叶子节点的个数

来源:百度知道 编辑:UC知道 时间:2024/06/23 14:35:58
如题,请高手不聆赐教

typedef struct bitnode
{
char data;
struct bitnode *lchild,*rchild;
}bitnode,*bitree;//二叉树类型
int inordernotleaf(bitree root)//中根遍历求非叶子节点个数,root是根指针
{
int notleaf=0;//notleaf是非叶子节点个数
bitree s[100];//s足够大
int top=0;
while(root||top)
{
while(root)
{
s[++top]=root;root=root->lchild;
}
if(top)
{
notleaf++;
root=s[top--]->rchild;
}
}
return notleaf;
}