一、树
一棵树总的来说就是一些数的集合,存在着各自的对应条件
(1)每个元素成为结点。
(2)有一个特点的结点,成为根,只有一个。
(3)从根节点开始往下分为m(m>=0)个树。又称为一个子树。
二、树的储存结构
(1)父亲表示法
const int m=10;
typedef struct node;
typedef node * tree;
struct node
{
char date;
tree child[m];
};
tree t;
缺点:只能从根部遍历到子节点,不能反找。
(2)父亲孩子表示法
const int m=10;
typedef struct node;
typedef node * tree;
struct node
{
char date;
tree child[m];
tree father;
};
tree t;
(3)孩子表示法
const int m=10;
typedef struct node;
typedef node * tree;
struct node
{
char date;
tree child[m];
};
tree t;
(4)孩子兄弟表示法
typedef struct node;
typedef node * tree;
struct node
{
char date;
tree firstchild,next;
};
tree t;
三、树的遍历
(1)先序遍历:先访问根节点,然后从左到右按照先序思想遍历。
(2)后序遍历:先从左到右遍历各个子树,再访问根节点。
(3)层次遍历:按层次从小到大逐个访问,同一层次按照从左到右的顺序。
四、个人感悟
学习慢慢的紧张了起来,现在回想起来,自己以前的学习就是泛泛学了一层表面的知识,回想起来好像什么都抓不住。