//建立二叉树的二叉链表存储结构
#include <stdio.h>
#include <stdlib.h>
typedef struct BiTreeNode{
char elem;
struct BiTreeNode *lchild,*rchild;
}BiTreeNode,*BiTree;
BiTree Creat_Tree(BiTree T){
char s,s1;
T =(BiTree)malloc(sizeof(BiTreeNode));
s = getchar();
s1=s;
s =getchar();
T->lchild=NULL;
T->rchild=NULL;
if(s1 == ',')
{
T->elem=s;
s1 = getchar();
if(s1=='(')
{
T->lchild = Creat_Tree(T->lchild);
T->rchild = Creat_Tree(T->rchild);
}
}
else
{
T->elem = s1;
if(s == '(')
{
T->lchild = Creat_Tree(T->lchild);
T->rchild = Creat_Tree(T->rchild);
}
}
return T;
}
void DLR(BiTree T){
if(T != NULL)
{
printf("%c",T->elem);
DLR(T->lchild);
DLR(T->rchild);
}
}
int main(){
BiTree t1;
t1 = Creat_Tree(t1);
DLR(t1);
return 0;
}
noj15 建立二叉树的二叉链表存储结构
最新推荐文章于 2023-06-03 11:00:15 发布