请按照下面的核心代码进行更改#include #include struct node{ char info; struct node *llink,*rlink; }; typedef struct node NODE; NODE *creat(){ char x; NODE *p; scanf("%c",&x); printf("%c",x); if(x!='.'){ p=(NODE *)malloc(sizeof(NODE)); p->info=x; p->llink=creat(); p->rlink=creat(); } else p=NULL; return p; } void run(NODE *t){ if(t){ run(t->llink); run(t->rlink); printf("%c",t- >info); } } main() { NODE *T; printf("PLease input a tree:\n"); T=creat(); printf("\n"); if(!T) printf("This is a empty binary tree."); else { printf("The result of post travese is:\n "); run(T); } printf("\n"); }
时间: 2024-01-12 22:04:56 浏览: 72
好的,根据你提供的代码,我们可以将其修改为按照题目要求进行输入和输出的程序。具体的实现可以参考下面的代码:
```c
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
char info;
struct node *llink, *rlink;
} NODE;
NODE* creat() {
char x;
NODE* p;
scanf("%c", &x);
if (x == '.') {
printf(".");
p = NULL;
} else {
p = (NODE*)malloc(sizeof(NODE));
p->info = x;
p->llink = creat();
p->rlink = creat();
}
return p;
}
void run(NODE* t) {
if (t) {
run(t->llink);
run(t->rlink);
printf("%c", t->info);
}
}
int main() {
NODE* T;
printf("Please input a tree:\n");
T = creat();
printf("\n");
if (!T) {
printf("THIS IS A EMPTY BINARY TREE\n");
} else {
printf("The result of post travese is:\n");
run(T);
printf("\n");
}
return 0;
}
```
输入样例:ABD..EH...CF.I..G..
输出样例:DHEBIFGCA
阅读全文