输出以二叉树表示的算术表达式(严6.51)--------西工大noj

 题解

这道题目说的很诡异,其实没有什么把括号补上。。。。仅仅是先序读入,然后中序输出就行了

代码

#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##
*/

posted @   心坚石穿  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示