コード例 #1
0
        private void PerformInsertionReordering4(RedBlackTree <T> newNode)
        {
            RedBlackTree <T> k = newNode;
            RedBlackTree <T> p = this;
            RedBlackTree <T> g = parent;
            RedBlackTree <T> s = Sibling;

            RedBlackTree <T> newG = new RedBlackTree <T>(g.content);

            newG.color        = "Red";
            newG.leftTree     = s;
            s.parent          = newG;
            newG.rightTree    = p.leftTree;
            p.leftTree.parent = newG;

            g.content   = p.content;
            g.leftTree  = newG;
            newG.parent = g;
            g.rightTree = k;
            k.parent    = g;
        }
コード例 #2
0
        private void PerformInsertionRecoloring(RedBlackTree <T> newNode)
        {
            RedBlackTree <T> k = newNode;
            RedBlackTree <T> p = this;
            RedBlackTree <T> g = parent;
            RedBlackTree <T> s = Sibling;

            g.color = "Red";
            p.color = "Black";
            s.color = "Black";

            // Handle case if g is the root node
            if (g.parent == null)
            {
                g.color = "Black";
            }

            else if (g.parent.color == "Red")
            {
                g.parent.RebalanceTree(g);
            }
        }
コード例 #3
0
 public RedBlackTree(T item)
 {
     content   = item;
     leftTree  = new RedBlackTree <T>();
     rightTree = new RedBlackTree <T>();
 }