双亲表示法
/* 树的双亲表示法结点结构定义 */
#define MAX_TREE_SIZE 100
typedef int TElemType; // 树结点的数据类型,目前暂定为整型
// 结点结构
typedef struct PTNode
{
TElemType data; // 结点数据
int parent; // 双亲位置
} PTNode;
// 树结构
typedef struct
{
PTNode nodes[MAX_TREE_SIZE]; // 结点数组
int r,n; // 根的位置和结点数
} PTree;
孩子表示法
/* 树的孩子表示法结构定义 */
#define MAX_TREE_SIZE 100
typedef int TElemType; // 树结点的数据类型,目前暂定为整型
// 孩子结点
typedef struct CTNode
{
int child;
struct CTNode *next;
} *ChildPtr;
// 表头结构
typedef struct
{
TElemType data;
ChildPtr firstchild;
} CTBox;
// 树结构
typedef struct
{
CTBox nodes[MAX_TREE_SIZE]; // 结点数组
int r,n; // 根的位置和结点数
} CTree;
孩子兄弟表示法
/* 树的孩子兄弟表示法结构定义 */
typedef int TElemType; // 树结点的数据类型,目前暂定为整型
typedef struct CSNode
{
TElemType data;
struct CSNode *firstchild,*rightsib; // 孩子 和 右兄弟
} CSNode,*CSTree;