#include<stdio.h>
#include<stdlib.h>
typedef char ElementType;
typedef struct TNode *BinTree;
struct TNode{
ElementType Data;
BinTree Left;
BinTree Right;
};
void Read_Preorder(BinTree BT)
{
ElementType Tdata;
Tdata=getchar();
if(Tdata!='\n'){
if(Tdata!='#'){
BT=(BinTree)malloc(sizeof(struct TNode));
BT->Data=Tdata;
Read_Preorder(BT->Left);
Read_Preorder(BT->Right);
}
else BT=NULL;
}
}
int DepthBTree(BinTree BT)
{
int RDepth, LDepth;
if(BT!=NULL){
LDepth=DepthBTree(BT->Left);
RDepth=DepthBTree(BT->Right);
return 1+((LDepth>RDepth)?LDepth:RDepth);
}
else return 0;
}
void PreorderTraversal(BinTree BT)
{
if(BT!=NULL){
printf("%c(%d)",BT->Data,DepthBTree(BT));
PreorderTraversal(BT->Left);
PreorderTraversal(BT->Right);
}
}
int main()
{
BinTree BT,BT1;
ElementType Tdata;
Read_Preorder(BT);
PreorderTraversal(BT);
return 0;
}
#include<stdlib.h>
typedef char ElementType;
typedef struct TNode *BinTree;
struct TNode{
ElementType Data;
BinTree Left;
BinTree Right;
};
void Read_Preorder(BinTree BT)
{
ElementType Tdata;
Tdata=getchar();
if(Tdata!='\n'){
if(Tdata!='#'){
BT=(BinTree)malloc(sizeof(struct TNode));
BT->Data=Tdata;
Read_Preorder(BT->Left);
Read_Preorder(BT->Right);
}
else BT=NULL;
}
}
int DepthBTree(BinTree BT)
{
int RDepth, LDepth;
if(BT!=NULL){
LDepth=DepthBTree(BT->Left);
RDepth=DepthBTree(BT->Right);
return 1+((LDepth>RDepth)?LDepth:RDepth);
}
else return 0;
}
void PreorderTraversal(BinTree BT)
{
if(BT!=NULL){
printf("%c(%d)",BT->Data,DepthBTree(BT));
PreorderTraversal(BT->Left);
PreorderTraversal(BT->Right);
}
}
int main()
{
BinTree BT,BT1;
ElementType Tdata;
Read_Preorder(BT);
PreorderTraversal(BT);
return 0;
}