typedef struct tree//二叉树的定义
{ char data; struct tree *lchild,*rchild; }TREE,*Tree;
void create(Tree t)//创建一棵二叉树
{ char ch; scanf("%c",&ch); if(ch=='#') t=NULL;
else { t->data=ch; create(t->lchild); create(t->rchild); }
}
int deep(Tree t)//深度算法
{ if(!t) return 0; else { ld=deep(t->lchild); rd=deep(t->rchild);
if(ld>rd) return rd+1; else return ld+1;
}
void main()//主函数
{ Tree t; create(t); printf("%d\n",deep(t)); } |