1 条题解
-
0
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct no { char data; struct no *lc,*rc; } node; void p(node *root)//输出 { if(root) { printf("%c",root->data); p(root->lc); p(root->rc); } } node *creat(node *root,char x) { if(root==NULL) { root=(node *)malloc(sizeof(node)); root->data=x; root->lc=root->rc=NULL; } else if(x>root->data) root->rc=creat(root->rc,x); else if(x<root->data) root->lc=creat(root->lc,x); return root; } int main() { char a,que[503]; int top=0,i; node *root; memset(que,0,sizeof(que)); root=NULL; while(scanf("%c",&a)!=EOF) { if(a>='A'&&a<='Z') que[top++]=a; else if(a=='*'||a=='$') { for(i=top-1; i>=0; i--) { root=creat(root,que[i]); } p(root); printf("\n"); memset(que,0,sizeof(que)); top=0; root=NULL; } if(a=='$')break; } return 0; }
- 1
信息
- ID
- 578
- 时间
- 1000ms
- 内存
- 10MiB
- 难度
- 9
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者