- the five properties of red and black trees (nature four and nature five are of particular importance)
1. The node must be red or black
2. The root node is black
3. All the leaf nodes are black.
4. The two child nodes of each red node are black, that is, no parent or child two nodes are all red.
5. The number of black nodes on all simple paths from any node to each of its leaf nodes is the same.
Note the following two points:
- new node is red child
- two fork tree left branch to discuss, right branch opposite can
If the Father node is black, then insert it directly! ()
If, Father node is black, its uncle is red, then, directly to turn grandfather into red, then, father and uncle turn black! ()
If, the Father node is red, its uncle is black, then, the new node is the right child, then left first, turned into a third situation! ()
If, the Father node is red, its uncle is black, then the node is left child, then proceed with (Grandfather's node) turn right! ()
The principle and realization of inserting the red and black tree