**
统计利用先序遍历创建的二叉树的宽度
**
#include
#include<malloc.h>
using namespace std;
struct tree{
char data;
tree *lchild;
tree *rchild;
};
void creat(tree *&t){
char ch;
cin>>ch;
if(ch=='#') t=NULL;
else{
t=new tree;
t->data=ch;
creat(t->lchild);
creat(t->rchild);
}
}
int height(tree *t){
if(t){
int l=height(t->lchild);
int r=height(t->rchild);
return l>r?l+1:r+1;
}
else return 0;
}
void width(tree *t,int a[],int h){
if(t==NULL) return;
else{
a[h]++;
width(t->lchild,a,h+1);
width(t->rchild,a,h+1);
}
}
int main(){
int a[100]={0};
tree *t;
creat(t);
int H=height(t);
width(t,a,0);
int max=a[0];
for(int i=0;i<H;i++){
if(max<a[i]) max=a[i];
}
cout<<max;
return 0;
}