📄 11.cpp
字号:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define null 0
typedef struct node
{ char data;
struct node *son;
struct node *brother;
}* bitree;
int i,j;
int chose(bitree t)
{if(t->brother!=null)return 0;
else return 1;
}
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->son);//建立儿子节点
setup(t->brother);//建立兄弟节点
}
return 1;
}
int travl(bitree t)
{if(t)
{ if(t->son!=null){i=i+1;travl(t->son);}//访问儿子
if(t->brother!=null){travl(t->brother);}//访问兄弟
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);
if(!chose(t)){
printf("输入错误!");
}
else{travl(t);
deep=j+1;
printf("深度为:%d",deep);
printf("\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -