70,020
社区成员




//头文件
#include "mod.h"
#include <stdlib.h>
typedef char ElementType;
typedef struct BinTree {
ElementType data;
BinTree* rchild;
BinTree* lchild;
}BinTree;
BinTree* creatTree();//建立二叉树
void postTree(BinTree* tree);//遍历二叉树(先序)
//函数文件
//#include "mod.h"
//#include <stdlib.h>
BinTree* creatTree() {
BinTree* binTree;
char c = getchar();
if (c == '#') {
return NULL;
}
binTree = (BinTree*)malloc(sizeof(BinTree));
binTree->data = c;
binTree->lchild=creatTree();
binTree->rchild = creatTree();
return binTree;
}
void postTree(BinTree* tree) {
if (tree == NULL) {
return;
}
printf("%s ",tree->data);
postTree(tree->lchild);
postTree(tree->rchild);
return;
}
//主文件
//#include "mod.h"
//#include <stdio.h>
int main(){
BinTree* a ;
a = creatTree();
postTree(a);
return 0;
}
报语法错误就把报错截图完整贴上来,这样肯于为你解决问题的人看一眼就行,免得还得动手编译,挺麻烦的,有劝退效应。
#include <stdio.h>
// ...
printf("%c", tree->data);