# include <stdio.h>
# include <malloc.h>
typedef struct tree
{
int data;
struct tree* lchild;
struct tree* rchild;
}Tree,*Ptree;
void travel(Ptree T);
void exchange(Ptree T);
void main()
{
Ptree a=(Ptree)malloc(sizeof(Tree));
Ptree b=(Ptree)malloc(sizeof(Tree));
Ptree c=(Ptree)malloc(sizeof(Tree));
Ptree d=(Ptree)malloc(sizeof(Tree));
Ptree e=(Ptree)malloc(sizeof(Tree));
a->data=8;
b->data=1;
c->data=2;
d->data=6;
e->data=5;
a->lchild=b;
a->rchild=c;
b->lchild=NULL;
b->rchild=d;
c->lchild=e;
c->rchild=NULL;
d->lchild=NULL;
d->rchild=NULL;
e->lchild=NULL;
e->rchild=NULL;
//travel(a);
exchange(a);
travel(a);
}
void travel(Ptree T)
{
if(T->lchild!=NULL)
travel(T->lchild);
printf("%d\n",T->data);
if(T->rchild!=NULL)
travel(T->rchild);
}
void exchange(Ptree T)
{
if(T->lchild!=NULL)
exchange(T->lchild);
if(T->rchild!=NULL)
exchange(T->rchild);
if(T!=NULL)
{
Ptree t;
t=T->lchild;
T->lchild=T->rchild;
T->rchild=t;
}
}
# include <malloc.h>
typedef struct tree
{
int data;
struct tree* lchild;
struct tree* rchild;
}Tree,*Ptree;
void travel(Ptree T);
void exchange(Ptree T);
void main()
{
Ptree a=(Ptree)malloc(sizeof(Tree));
Ptree b=(Ptree)malloc(sizeof(Tree));
Ptree c=(Ptree)malloc(sizeof(Tree));
Ptree d=(Ptree)malloc(sizeof(Tree));
Ptree e=(Ptree)malloc(sizeof(Tree));
a->data=8;
b->data=1;
c->data=2;
d->data=6;
e->data=5;
a->lchild=b;
a->rchild=c;
b->lchild=NULL;
b->rchild=d;
c->lchild=e;
c->rchild=NULL;
d->lchild=NULL;
d->rchild=NULL;
e->lchild=NULL;
e->rchild=NULL;
//travel(a);
exchange(a);
travel(a);
}
void travel(Ptree T)
{
if(T->lchild!=NULL)
travel(T->lchild);
printf("%d\n",T->data);
if(T->rchild!=NULL)
travel(T->rchild);
}
void exchange(Ptree T)
{
if(T->lchild!=NULL)
exchange(T->lchild);
if(T->rchild!=NULL)
exchange(T->rchild);
if(T!=NULL)
{
Ptree t;
t=T->lchild;
T->lchild=T->rchild;
T->rchild=t;
}
}