题解
这道题目说的很诡异,其实没有什么把括号补上。。。。仅仅是先序读入,然后中序输出就行了
代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct TreeNode
{
char data;
struct TreeNode *LChild, *RChild;
}TreeNode;
char *c;
void Create(TreeNode **T)
{
if(*c=='#')
{
(*T) = NULL;
c++;
return ;
}
(*T) = (TreeNode*)malloc(sizeof(TreeNode));
(*T)->data = *c;
c++;
Create(&(*T)->LChild);
Create(&(*T)->RChild);
}
void Print(TreeNode*T)
{
if(!T)
return;
Print(T->LChild);
printf("%c",T->data);
Print(T->RChild);
}
int main()
{
static char buf[10000];
scanf("%s",buf);
c = buf;
TreeNode *T;
Create(&T);
Print(T);
return 0;
}
/*
*+a(###b#)##c##
*/