#include <iostream>
#include <stdlib.h>
using namespace std;
typedef struct BiTNode
{
int data;
struct BiTNode *lc,*rc;
} BitNode,*BiTree;
void CreateTree(BiTNode *T)
{
T=(BiTNode *)malloc(sizeof(BiTNode));
int data;
cin>>data;
if(data==0)
{
T->data='#';
}
else
{
T->data=data;
CreateTree(T->lc);
CreateTree(T->rc);
}
}
void pre_order(BiTree T)
{
if(T->data!=1)
{
cout<<T->data<<" ";
pre_order(T->lc);
pre_order(T->rc);
}
}
void in_order(BiTree T)
{
if(T->data!=1)
{
in_order(T->lc);
cout<<T->data<<" ";
in_order(T->rc);
}
}
void post_order(BiTree T)
{
if(T->data!=1)
{
post_order(T->lc);
post_order(T->rc);
cout<<T->data<<" ";
}
}
int main()
{
BitNode T;
CreateTree(&T);
pre_order(&T);
cout<<endl;
in_order(&T);
cout<<endl;
post_order(&T);
return 0;
}
#include <stdlib.h>
using namespace std;
typedef struct BiTNode
{
int data;
struct BiTNode *lc,*rc;
} BitNode,*BiTree;
void CreateTree(BiTNode *T)
{
T=(BiTNode *)malloc(sizeof(BiTNode));
int data;
cin>>data;
if(data==0)
{
T->data='#';
}
else
{
T->data=data;
CreateTree(T->lc);
CreateTree(T->rc);
}
}
void pre_order(BiTree T)
{
if(T->data!=1)
{
cout<<T->data<<" ";
pre_order(T->lc);
pre_order(T->rc);
}
}
void in_order(BiTree T)
{
if(T->data!=1)
{
in_order(T->lc);
cout<<T->data<<" ";
in_order(T->rc);
}
}
void post_order(BiTree T)
{
if(T->data!=1)
{
post_order(T->lc);
post_order(T->rc);
cout<<T->data<<" ";
}
}
int main()
{
BitNode T;
CreateTree(&T);
pre_order(&T);
cout<<endl;
in_order(&T);
cout<<endl;
post_order(&T);
return 0;
}