用递归交换二叉树的左右子树,用c++实现。请高手写出完整的程序,包括头文件和主函数

来源:百度知道 编辑:UC知道 时间:2024/05/02 20:10:25
要完整的,不只是算法。

#include "stdio.h"
#include "conio.h"

typedef struct node
{int data;
struct node *lchild,*rchild;
}bitree;

typedef int datatype;

typedef struct
{datatype data[64];
int top;
}seqstack;
seqstack *s;

bitree *creat()
{bitree *t;
int x;
printf("0 for NULL");
scanf("%d",&x);
if (x==0)
t=NULL;
else
{t=(bitree *)malloc(sizeof(bitree));
t->data=x;
t->lchild=creat();
t->rchild=creat();
}
return t;
}

void inorder(bitree *t)
{if (t!=NULL)
{inorder(t->lchild);
printf("%4d",t->data);
inorder(t->rchild);
}
}

void exchange(bitree *t)
{bitree *p;
if (t!=NULL)
{p=t->lchild;
t->lchild=t->rchild;
t->rchild=p;
exchange(t->lchild);
exchange(t->