树存储结构

双亲表示法数据结构:

typedef struct  Node{
	char data;
	int parent;
}PTNode;
typedef struct{
	PTNode nodes[100];
	int n;
}PTree;

兄弟表示法数据结构

typedef struct CSNode{
    ElemType data;
    struct CSNode * firstchild,*nextsibling;
}CSNode,*CSTree;

孩子表示法数据结构

//孩子表示法
typedef struct CTNode{
    int child;//链表中每个结点存储的不是数据本身,而是数据在数组中存储的位置下标
    struct CTNode * next;
}*ChildPtr;
typedef struct {
    TElemType data;//结点的数据类型
    ChildPtr firstchild;//孩子链表的头指针
}CTBox;
typedef struct{
    CTBox nodes[Tree_Size];//存储结点的数组
    int n,r;//结点数量和树根的位置
}CTree

如图所示的树,给出该树的双亲表示法和孩子兄弟表示法的图示

答:

猜你喜欢

转载自blog.csdn.net/weixin_42034217/article/details/84965551