//树的链式存储--双亲表示法
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_TREE_SIZE 100
typedef struct BPTNode
{
char data;//数据域
int parentPosition; //双亲的数组下标
char LRTag; //左右孩子标志域
}BPTNode;
typedef struct BPTree
{
BPTNode nodes[100]; //因为节点之间是分散的,需要把节点存储到数组中
int num_node; //节点数目
int root; //根结点的位置 //注意此域存储的是父亲节点在数组的下标
}BPTree;
void Test1(){
BPTNode t1, t2, t3, t4, t5,t6;
BPTree bt;
bt.nodes[0] = t1;
bt.nodes[1] = t2;
bt.nodes[2] = t3;
bt.nodes[3] = t4;
bt.nodes[4] = t5;
bt.nodes[5] = t6;
bt.num_node = 6;
bt.root = 0;
t1.data = 'A';
t1.LRTag = '0';
t1.parentPosition = '-1';
t1.data = 'B';
t1.LRTag = '0';
t1.parentPosition = '0';
t1.data = 'C';
t1.LRTag = '1';
t1.parentPosition = '0';
t1.data = 'D';
t1.LRTag = '0';
t1.parentPosition = '1';
t1.data = 'E';
t1.LRTag = '1';
t1.parentPosition = '1';
t1.data = 'F';
t1.LRTag = '1';
t1.parentPosition = '2';
}
void main(){
system("pause");
}
![]()