樹的存儲結構

一、樹的表示方法
1、雙親表示法

struct node
{
    int data;//節點數據
    int parent;//父節點在數組中的下標

};

2、孩子表示法
由兩部分組成
1、表頭形成的循序表,存放節點數據和第一個孩子的地址
2、孩子鏈表。有此節點的孩子節點組成的單鏈表

struct CTNode
{
    int data;
    CTNode *next;

};
struct CBNode{
    int data;
    CTNode *firstChild;
};

3、孩子兄弟表示法

struct node{
	//節點數據
    int data;
    //firstChild第一個兒子的地址,rightBrother右兒子的地址
    node *firstChild,*rightBrother
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章