回 帖 发 新 帖 刷新版面

主题:新手求助,二叉树类的定义和实现的程序填空

高手帮忙,刚接触,无头绪啊,谢谢啦

typedef struct BinNode{
    int data; 
    struct BinNode* leftchild, * rightchild;
}BinNode, *BinTree;

void InitBinTree(BinTree &root)  //初始化二叉树root
{
   root=Null;
}

void DestroyBinTree(BinTree &root)  //销毁二叉树root
{
if (root == NULL) return;
   DestroyBinTree(root->leftchild);  
DestroyBinTree (root->rightchild);
free(root);
}

int countNodes1(BinTree &root)  //计算二叉树root中度为1的结点数

   if (   ① ___________ if(root!=NULL) ___________________                  ){
       if(root-> leftchild!=NULL && root-> rightchild!=NULL)
            ___②___ return root _________________________________________________;
       else  if(root-> leftchild==NULL && __③__ _______________________________ ___)
__④_ ___________________________________________________________;
else if (root-> leftchild!=NULL &&    ⑤    _____________________________   )
      __⑥_ ___________________________________________________________;
}
   return 0;
}

回复列表 (共3个回复)

沙发

[em7]为什么高手都不出手呢?[em7][em7]

板凳

跪求高手了,出手相助吧.

3 楼

我想这里的度是指出度吧。。。如果是这样:


int countNodes1(BinTree &root)  //计算二叉树root中度为1的结点数

   if (   ① ___________ if(root!=NULL) ___________________                  ){
       if(root-> leftchild!=NULL && root-> rightchild!=NULL)
            ___②___ return countNodes1(root->leftchild)+countNodes1(root->rightchild); _________________________________________________;
       else  if(root-> leftchild==NULL && __③__ ________root->rightchild!=NULL ___)
__④_ ___________return 1+countNodes1(root->rightchild);_________________________________;
else if (root-> leftchild!=NULL &&    ⑤    ____root->rightchild==NULL_____________   )
      __⑥_ ________return 1+countNodes1(root->leftchild);________________________________;
}
   return 0;
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册