樹的存儲
來源:程序員人生 發布時間:2014-12-13 08:41:45 閱讀次數:3727次
樹的存儲方式
//樹的雙親表示
typedef struct{ //節點結構
ElemType data; //元素
int parent; //雙親位置
}PTNode;
typedef struct{ //樹
PTNode nodes[Max];
int n; //樹的節點個數
}PTree;
//孩子表示法
typedef struct{ //孩子結點
int child; //孩子位置
struct CNode* next;
}CNode;
typedef struct{
ElemType data;
CNode *next; //指向第1個孩子的指針
}PNode,PTree[Max];
//孩子兄弟表示法
typedef struct CSNode{
ElemType data;
struct CSNode *firstchilde,*nextsibling;
}CSNode,*CSTree;
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈