数据库第三天

递归二叉树

`#include<stdio.h>
#include<malloc.h>
typedef struct Node{
char data;
struct Node lchild,rchild;
}bintree;
bintree
creat(){
bintree
tree;
char x=getchar();
if(x==’#’) return NULL; //这个函数没有返回类型不能返回NULL
tree=(bintree*)malloc(sizeof(bintree));
tree->lchild=NULL; tree->rchild=NULL;
tree->data=x;
tree->lchild=creat();
tree->rchild=creat();
return tree;
}
void preorder(bintree* tree){
if(tree==NULL) return NULL;
printf("%c ",tree->data);
preorder(tree->lchild);
preorder(tree->rchild);

}
void inorder(bintree* tree){
if(treeNULL) return NULL;
inorder(tree->lchild);
printf("%c ",tree->data);
inorder(tree->rchild);
}
void postorder(bintree* tree){
if(tree
NULL) return NULL;
postorder(tree->lchild);
postorder(tree->rchild);
printf("%c “,tree->data);
}
main(){
bintree *tree;
tree=creat();
preorder(tree);
printf(”\n");
inorder(tree);
printf("\n");
postorder(tree);
}
//ABD###CE##F##
``

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值