所以我有一棵如下的红黑树:
2 = Root Black
Children = 1 (Black/Left), 4 (Red/Right)
Children of 1 = NIL & NIL => Height of Black Subtree is then 2
Children of 4 = 3 (Black/Left), 5 (Black/Right)
Children of 3 = NIL & NIL, Height of Black Subtree is then 2
Children of 5 = 7 (Red/Right)& NIL, Height is still then of course 2.
所以当我插入6(当然颜色是红色)时,它就是7的左孩子。在我关注的这个web应用程序中,它在6和7之间轮换。为什么?在我看来,这似乎没有违反RBT的任何属性。
注意:源web应用程序是一个Java web应用程序,需要1.7来源:http://gauss.ececs.uc.edu/RedBlackTester/redblack.html
RBT的属性是。
因此,如果7是红色的,当添加6时,它也是红色的,这违反了第三个属性,因此进行旋转和更改以消除违规。