版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CSDN___CSDN/article/details/83547190
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
char data;
struct node *rchild,*lchild;
}bintnode;
typedef bintnode *bintree;//指向该结构体的指针
/*二叉树遍历的递归实现*/
/*前序遍历*/
void preorder(bintree t)
{
if(t)
{
printf("%d",t->data);
preorder(t->lchild);
preorder(t->rchild);
}
}
/*中序遍历*/
void inorder(bintree t)
{
if(t)
{
inorder(t->lchild);
printf("%d",t->data);
inorder(t->rchild);
}
}
/*后序遍历*/
void postorder(bintree t)
{
if(t)
{
postorder(t->lchild);
postorder(t->rchild);
printf("%d",t->data);
}
}
/*根据前序遍历的结果创建一棵二叉树*/
bintree creatbintree()
{
char ch;
bintree t;
if((ch=getchar())=='#')
{
t=NULL;
}
else
{
t=(bintnode*)malloc(sizeof(bintnode));
t->data=ch;
t->lchild=creatbintree();
t->rchild=creatbintree();
}
return t;
}
int main ()
{
bintree node;
return 0;
}