#include <stdio.h>
typedef struct _Tri Tri,*PTri;
struct _Tri{
char data;
int Lft;
int Rght;
};
typedef struct _Tree Tree,*tree;
#define Null -1
#define MAX_TREE_SIZE 100
struct _Tree{
Tri nodes[MAX_TREE_SIZE+1];
int _Root_;
};
static void _Estab_(tree *pTree)
{
int N;
scanf("%d",&N);
int Chk[N+1] = {0};
for(int i = 1;i <= N;++i)
{
char data,Lft,Rght;
scanf("%c%c%c",&data,&Lft,&Rght);
(*pTree)->nodes[i].data = data;
if(Lft == '^') (*pTree)->nodes[i].Lft = Null;
else{
(*pTree)->nodes[i].Lft = Lft-'0';
Chk[Lft-'0'] = 1;
}
if(Rght == '^') (*pTree)->nodes[i].Rght = Null;
else{
(*pTree)->nodes[i].Rght = Rght-'0';
Chk[Rght-'0'] = 1;
}
}
register int i;
for(i = 1;i <= N;++i)
{
if(!Chk[i]) break;
}
(*pTree)->_Root_ = i;
}
三元组结构体数组表示二叉树 | 静态链表
最新推荐文章于 2024-09-11 20:39:26 发布