doc: add tree section to data structure post

This commit is contained in:
Leon Xu committed 2022-03-15 18:20:10 -07:00
1 parent 42053aa004
commit cec34efb4a
1 file changed
+30 -1
+30 -1
View File
@@ -8,7 +8,7 @@ categories:
- 数据结构
abbrlink: 79666db
date: 2022-02-08 12:39:47
updated: 2022-02-26 17:00:00
updated: 2022-03-15 17:00:00
---
感觉好久没有更新网站了,一直在忙着修改简历和学习新的技术,所以就一直没有更新过。
今天呢,就跟大家说一下常见的数据结构,很多的教材有自己的分类,但是常见的数据结构有8大类![数据结构](/images/数据结构.png)
@@ -65,4 +65,33 @@ class ListNode {
this.val = val;
}
}
```
## Tree(树)
树是一种数据结构,它是由n(n>=1)个有限节点组成一个具有层次关系的集合。把它叫做 “树” 是因为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的。它具有以下的特点:
- 每个节点有零个或多个子节点;
- 没有父节点的节点称为根节点;
- 每一个非根节点有且只有一个父节点;
- 除了根节点外,每个子节点可以分为多个不相交的子树;
![Binary Search Tree](/images/binary-search-tree.png)
Binary Tree二叉树是树的特殊一种,具有如下特点:
1. 每个结点最多有两颗子树
2. 左子树和右子树是有顺序的
初始化
TreeNode root = new TreeNode(0);
root.left = new TreeNode(1);
root.right = new TreeNode(2);
```java
class TreeNode {
int val;
TreeNode left;
TreeNode right;
public TreeNode(int val) {
this.val = val;
}
}
```