1. 题目
![](https://i-blog.csdnimg.cn/blog_migrate/ff84011fff2af698c997872d0ee865dd.png)
示例输入
*+a(###b#)##c##
示例输出
(a+b)*c
2. 代码
先序输入,中序输出。
//*+a(###b#)##c##
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
char data;
struct node *lchild;
struct node *rchild;
}BTree;
BTree *createBTree(){
char c = getchar();
if(c == '#'){
return NULL;
}
BTree *t = (BTree*) malloc(sizeof(BTree));
t->data = c;
t->lchild = createBTree();
t->rchild = createBTree();
return t;
}
void InOrderOutput(BTree *t){
if(t && t->data !='#'){
InOrderOutput(t->lchild);
printf("%c", t->data);
InOrderOutput(t->rchild);
}
}
int main(int argc, char *argv[]) {
BTree *t = createBTree();
InOrderOutput(t);
return 0;
}