For the principle and algorithm of red-black tree, I recommend everyone to read this blog: A detailed introduction to the principle and algorithm of red-black tree (1)
Here, I want to write some of my own experience, how to make the tree meet the rules of red-black tree in the process of color change and rotation. Please read it in conjunction with the blog above.