#include<stdio.h>
#include<stdlib.h>
typedef char ElemType;
typedef struct BiTNode
{
ElemType data;
struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree;
BiTree Create()
{
ElemType ch;
BiTree T;
scanf("%c", &ch);
if (ch == '#') return NULL;
T = (BiTree)malloc(sizeof(struct BiTNode));
T->data = ch;
T->lchild = Create();
T->rchild = Create();
return T;
}
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);
//cout << T->data;
printf("%c", T->data);
Inorder(T->rchild);
}
}
void Postorder(BiTree T)//后序
{
if (T)
{
Postorder(T->lchild);
Postorder(T->rchild);
printf("%c", T->data);
//cout << T->
二叉树的三种遍历(C实现)
最新推荐文章于 2024-07-17 17:13:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)