输入:abd##e##cf###
输出结果:3
运行环境.cpp
注意:若无运行结果,则一定是建树错误

#include "bits/stdc++.h"
using namespace std;
typedef struct BiTNode{
    char data;
    struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
void createTree(BiTree  &t){
    char ch;
    ch=getchar();
    if (ch=='#') t=NULL;
    else{
        t=(BiTNode *) malloc(sizeof (BiTNode));
        t->data=ch;
        t->lchild=NULL;
        t->rchild=NULL;
        createTree(t->lchild);
        createTree(t->rchild);
    }
}
int btDepth(BiTree t){
    if (!t)
        return 0;
    int front=-1,rear=-1;
    int last=0;
    int m=0;//
    BiTree Q[100];
    Q[++rear]=t;
    BiTree p;
    while (front<rear){
        p=Q[++front];
        if (p->lchild)
            Q[++rear]=p->lchild;
        if (p->rchild)
            Q[++rear]=p->rchild;
        if (front==last){
            last=rear;
            if (m<last-front)
                m=last-front;
        }
    }
    return m;
}
int main() {
  BiTree t;
  createTree(t);
  printf("%d", btDepth(t));
}
 
                


















