数据结结构学习 -- 树和森林

------树的双亲表示存储------

#define MAX_TREE_SIZE 100;

typedef struct PTNode {

  TElemType data;

  int parent;

}PTNode;

typedef struct {

  PTNode nodes[MAX_TREE_SIZE];

  int r,n;  //根的位置,和节点数

}PTree;

数组下标  

0   1   2  3  4  5  6  7  8  9

R   A  B  C  D  E  F  G  H  K

-1  0  0   0  1  1  3  6  6  6

 

------ 数的孩子链表存储表示------

typedef struct CTNode {  //孩子节点

  int child;

  struct CTNode * next;

}  *ChildPtr;

 typedef struct {

  TElemType data;

  ChildPtr firstchild;

}CTBox;

typedef struct {

  CTBox nodes [ MAX_TREE_SIZE];

  int n,r;

}CTree;

 

------ 数的二叉链表(孩子-兄弟)存储表示------

typedef struct CSNode {

  ElemType data;

  struct CSNode * firstchild, * nextsibling;

}CSNode, *CSTree;

 

 

posted on 2012-11-25 13:53  莫水千流  阅读(216)  评论(0编辑  收藏  举报