热门

最新

红包

立Flag

投票

同城

我的

发布
qq_54437317
qq_54437317
4 年前
trueqq_54437317

#include<stdio.h>#include<math.h>#include<stdlib.h>#include<malloc.h>#include<ctype.h>#define StackInitSize 100#define max 20#define lenBiTree sizeof(struct biTree)//二叉树节点typedef struct biNode{ char data; struct biNode *lchild; struct biNode *rchild;}biNode,*biTree;void ReadExpr(biTree *E){ char ch; scanf("c%",&ch); *E=(biTree)malloc(sizeof(biNode)); (*E)->data=ch; if((ch>='0'&&ch<='9')||(ch>='a'&&ch<='z')){ (*E)->lchild=NULL; (*E)->rchild=NULL; } else{ ReadExpr(&(*E)->lchild); ReadExpr(&(*E)->rchild); }}void WriteExpr(biTree *E){ if((*E)->lchild!=NULL){ printf("("); WriteExpr(&(*E)->lchild); } if(E!=NULL){ printf("%c",(*E)->data); } if((*E)->rchild!=NULL){ WriteExpr(&(*E)->rchild); printf(")"); }}int main(){ biTree *E; printf("输入表达式:\n"); ReadExpr(E); WriteExpr(E);}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
电脑开机显示欢迎使用闻到死
立即登录