private void RepairBlackUncle(RBNode <T> origin) { RBNode <T> grand = origin.Parent.Parent; RBNode <T> secondRotateNode = origin.Parent; if (grand.Right != null) { if (grand.Right.Left == origin) { secondRotateNode = RotateRight(origin.Parent, origin); } } if (grand.Left != null) { if (grand.Left.Right == origin) { secondRotateNode = RotateLeft(origin.Parent, origin); } } if (grand.Left == secondRotateNode) { RotateRight(grand, secondRotateNode); } else { RotateLeft(grand, secondRotateNode); } origin.Parent.SetColor(Color.Black); grand.SetColor(Color.Red); }
private void RepairRedUncle(RBNode <T> origin) { RBNode <T> uncle = GetUncle(origin); origin.Parent.SetColor(Color.Black); uncle.SetColor(Color.Black); origin.Parent.Parent.SetColor(Color.Red); RepairTree(origin.Parent.Parent); }
///<summary>binary insert, node color is set to RED</summary> private RBNode <T> InsertNode(RBNode <T> node) { if (root == null) { root = new RBNode <T>(Color.Red); return(root); } RBNode <T> current = root; int compResult = 0; while (true) { compResult = valueComparison(node.Value, current.Value); if (compResult < 0) { if (current.Left == null) { break; } else { current = current.Left; } } else { if (current.Right == null) { break; } else { current = current.Right; } } } node.SetParent(current); node.SetColor(Color.Red); if (compResult < 0) { current.SetLeft(node); } else { current.SetRight(node); } return(node); }
private void RepairRootNode(RBNode <T> origin) { origin.SetColor(Color.Black); }