树
#include<iostream>
using namespace std;
typedef struct node
{
int data;
struct node *rchild,*lchild;
}*tree,sq;
void build(tree &T,int a[],int i,int n)
{
if(i>=n)T=NULL;
else
{
T=(tree)malloc(sizeof(sq));
T->data=a[i];
build(T->lchild,a,2*i+1,n);
build(T->rchild,a,2*i+2,n);
}
}
void proprin(tree T)
{
if(T!=NULL)
{
cout<<T->data<<" ";
proprin(T->lchild);
proprin(T->rchild);
}
}
void pprin(tree T)
{
if(T!=NULL)
{
proprin(T->lchild);
cout<<T->data<<" ";
proprin(T->rchild);
}
v
}
void prprin(tree T)
{
if(T!=NULL)
{
proprin(T->lchild);
proprin(T->rchild);
cout<<T->data<<" ";
}
v
}
int deep(tree T)
{
int n,m;
if(T!=NULL)
{
n=deep(T->lchild);
m=deep(T->rchild);
return n>m?n+1:m+1;
}
else
return 0;
}
int main()
{
int a[100],i,m;
tree T;
int n;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
build(T,a,0,n);
pprin(T);
cout<<endl;
prprin(T);
cout<<endl;
m=deep(T);
cout<<m<<endl;
return 0;
}