?? 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 + -