//输出以二叉树表示的算术表达式
#include <stdlib.h>
#include <stdio.h>
typedef struct Node{
char elem;
struct Node *lchild,*rchild;
}Node,*NodePtr,* BiTreeP;
BiTreeP Creat_Tree(BiTreeP T){
char c = getchar();
if(c == '#')
{
T = NULL;
}
else
{
T = (BiTreeP)malloc(sizeof(Node));
T->lchild = NULL;
T->rchild = NULL;
T->elem = c;
T->lchild = Creat_Tree(T->lchild);
T->rchild = Creat_Tree(T->rchild);
}
return T;
}
void Print_Tree(BiTreeP T){
if(T != NULL)
{
Print_Tree(T->lchild);
printf("%c",T->elem);
Print_Tree(T->rchild);
}
}
int main(){
BiTreeP t1;
t1 = Creat_Tree(t1);
Print_Tree(t1);
return 0;
}
noj17 输出以二叉树表示的算术表达式
最新推荐文章于 2022-04-23 11:05:28 发布