-->
当前位置:首页 > 题库 > 正文内容

程序填空题:计算二叉树深度

Luz4年前 (2021-05-10)题库3057
计算二叉树深度。

```c++

#include
using namespace std;

typedef struct BiNode
{
char data;
struct BiNode *lchild,*rchild;
}BiTNode,*BiTree;


void CreateBiTree(BiTree &T)
{
char ch;
cin >> ch;
if(ch=='#') T=NULL;
else{
T=new BiTNode;
T->data=ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
}

int Depth(BiTree T)
{
int m,n;
if(@@[T == NULL ](2)) return 0;
else
{
@@[m=Depth(T->lchild)](2);
@@[n=Depth(T->rchild)](2);
if(m>n) return(m+1);
else return (n+1);
}
}

int main()
{
BiTree tree;
CreateBiTree(tree);
cout< return 0;

}
```






答案:
第1空:T == NULL

第2空:m=Depth(T->lchild)

第3空:n=Depth(T->rchild)

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。