树的常见的三种链表存储结构

1.双亲表示法:

// - - - - - 树的双亲表存储表示 - - - - -
#define MAX_TREE_SIZE 100
typedef struct PTNode { //结点结构
    ElemType data;
    int parent; //双亲位置域
}PTNode;
typedef struct { //树结构
    PTNode nodes[MAX_TREE_SIZE];
    int r,n; //根的位置和结点数 
}

树的双亲表示法

树的双亲表示法示例

2.树的孩子链表存储表示

// - - - - - 树的孩子链表存储表示 - - - - - 
typedef struct CTNode { //孩子节点
    int child;
    struct CSNode *next;    
}* ChildPtr;
typedef struct { //孩子链表头指针
    Elemtype data;
    ChildPtr firstchild;    
}CTBox;
typedef struct {
    CTBox nodes[MAX_TREE_SIZE];
    int n, r; //结点数和根的位置
}CTree;

这里写图片描述

树的孩子链表表示法示例

3.树的孩子兄弟表示法

// - - - - - 树的二叉链表(孩子-兄弟)存储表示 - - - - -
typedef struct CSNode {
    ElemType data;
    struct CSNode *firstchild, *nextsibling;
}CSNode, *CSTree;

这里写图片描述

树的二叉链表表示法示例

猜你喜欢

转载自blog.csdn.net/perry0528/article/details/82527739
今日推荐