📄 10.cpp
字号:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define null 0
typedef struct node
{ char data;
struct node *lchild;
struct node *rchild;
}* bitree;
int i,j;
int setup(bitree &t)
{char ch=' ';
scanf("%c",&ch);
if(ch==' ')t=null;
else{
if(!(t=(node *)malloc(sizeof(node))))return 0;
t->data=ch; //建立根节点
setup(t->lchild);//建立左子树
setup(t->rchild);//建立右子树
}
return 1;
}
int travl3(bitree t)//后序遍历的递归调用
{if(t)
{ if(t->lchild!=null){i=i+1;travl3(t->lchild);}//访问左子树
if(t->rchild!=null){i=i+1;travl3(t->rchild);}//访问右子树
if(i>j)j=i;
i=i-1;
return 1;
}
else return 0;
}
void main()
{bitree t=null;
i=0;j=0;
int deep;
printf("输入数值:");
setup(t);
travl3(t);
deep=j+1;
printf("二叉树深度为:");
printf("%d",deep);
printf("\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -