二叉树的储存及遍历
![在这里插入图片描述](https://img-blog.csdnimg.cn/039cff4ee70d4f5a8f25efa6e76188ac.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5ZKW5ZWhYmI=,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef struct BiTNode{
char data;
struct BiTNode *lchild,*rchild;
} BiTNode,*BiTree;
void CreateBiTree(BiTree &T){
char ch;
cin>>ch;
if(ch=='*') T=NULL;
else
{
T=(BiTNode *)malloc(sizeof(BiTNode));
T->data=ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
}
void Preorder(BiTree T){
if(T){
printf("%c ",T->data);
Preorder(T->lchild);
Preorder(T->rchild);
}
}
void Inorder(BiTree T){
if(T){
Inorder(T->lchild);
printf("%c ",T->data);
Inorder(T->rchild);
}
}
void Postorder(BiTree T){
if(T){
Postorder(T->lchild);
Postorder(T->rchild);
printf("%c ",T->data);
}
}
int main()
{
BiTree T;
CreateBiTree(T);
Postorder(T);
system("pause");
return 0;
}