1. 程式人生 > >樹儲存結構

樹儲存結構

雙親表示法資料結構:

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

如圖所示的樹,給出該樹的雙親表示法和孩子兄弟表示法的圖示

答: