#include<stdio.h>
#include <stdlib.h>
typedef struct BiTNode {
int data;
struct BiTNode *lchild, *rchild;
}BiTNode ,*BiTree;
BiTNode *f;
BiTNode *pre=NULL;
BiTNode *final=NULL;
void free (BiTNode *x){
x->lchild=NULL;
x->rchild=NULL;
}
void visit(BiTree t)
{
if(t==f)
{
final=pre;
printf("前驱为%d",final->data);
}
else{
pre=t;
}
printf("%d",t->data);
}
void midorder(BiTree t) //中序遍历
{
if(t!=NULL)
{
midorder(t->lchild);
visit(t);
midorder(t->rchild);
}
}
int main(){
BiTree a=NULL;
a=(BiTNode *)malloc(sizeof(BiTNode));
a->data=1;
free(a);
BiTNode *b=(BiTNode *)malloc(sizeof(BiTNode));
b->data=2;
a->lchild=b;
free (b) ;
BiTNode *c=(BiTNode *)malloc(sizeof(BiTNode));
c->data=3;
a->rchild=c;
free (c) ;
BiTNode *d=(BiTNode *)malloc(sizeof(BiTNode));
d->data=4;
b->lchild=d;
free (d) ;
BiTNode *e=(BiTNode *)malloc(sizeof(BiTNode));
e->data=5;
b->rchild=e;
free (e) ;
f=(BiTNode *)malloc(sizeof(BiTNode));
f->data=6;
c->lchild=f;
free (f) ;
BiTNode *g=(BiTNode *)malloc(sizeof(BiTNode));
g->data=7;
d->rchild=g;
free (g) ;
midorder(a);
return 0;
}