Skip to content

Commit 3ac8e54

Browse files
committed
Detailed explanation and index for redblack tree in readme
1 parent 52c93f9 commit 3ac8e54

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ So,if you wannt to view the notes which contains latex math formulas and are in
2121
* [README.md](./notes/README.md)
2222
* [sort.md](./notes/sort.md)
2323
* [tree.md](./notes/tree.md)
24+
* [red-black-tree.md](./notes/red-black-tree.md)
2425
* [algorithm](./algorithm)
2526
* [8Astar.py](./algorithm/8Astar.py)
2627
* [cantor.cc](./algorithm/cantor.cc)
@@ -32,6 +33,7 @@ So,if you wannt to view the notes which contains latex math formulas and are in
3233
* [sunday.py](./algorithm/sunday.py)
3334
* [dataStructure](./dataStructure)
3435
* [allOone](./dataStructure/allOone)
36+
* [redblack tree.py](./dataStructure/redBlackTree.py)
3537
* [binaryHeap.py](./dataStructure/binaryHeap.py)
3638
* [binaryIndexedTree.cc](./dataStructure/binaryIndexedTree.cc)
3739
* [binaryTree.py](./dataStructure/binaryTree.py)

notes/red-black-tree.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ tags: [数据结构,红黑树]
66
keywords:
77
mathjax: true
88
description:
9+
---
10+
911
<!-- TOC -->
1012

1113
- [1. 定义与性质](#1-定义与性质)
@@ -365,7 +367,11 @@ def find(root,i):
365367

366368
**[github地址](https://github.com/mbinary/algorithm-and-data-structure.git)**
367369

368-
我用了 setChild, getChild 来简化代码量, 其他的基本上是按照算法导论上的伪代码提到的case 来实现的. 然后display 只是测试的时候,为了方便调试而层序遍历打印出来
370+
我的代码有两点不同
371+
* 用了 setChild, getChild 来简化代码量
372+
* 每个结点没有上面的 p 域, 即指向 nil leaf的,我直接让 left, right 为 `None`, 然后定义了两个函数 `setBlack`, `checkBlack` 来操作 颜色数据 isBlack(当为 True 时代表黑色,否则为红). 如果为 None, 这两个函数也能正确的处理.可以直接见代码
373+
374+
其他的基本上是按照算法导论上的伪代码提到的case 来实现的. 然后display 只是测试的时候,为了方便调试而层序遍历打印出来
369375

370376
效果如下
371377
![](https://upload-images.jianshu.io/upload_images/7130568-721e18cc44dec604.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

0 commit comments

Comments
 (0)