Esempio n. 1
0
        public RBNode Right_rotate(RBNode rt)
        {
            var piv = rt.left;

            rt.left   = piv.right;
            piv.right = rt;
            return(piv);
        }
Esempio n. 2
0
        public void Insert(int value)
        {
            var node = new RBNode(value);

            node.color = true;
            root       = Insert(root, node);
            //Fix(ref root, node);
        }
Esempio n. 3
0
 public void print_tree(RBNode n, int step, List <List <int> > lst)
 {
     if (n.right != null)
     {
         print_tree(n.right, step + 1, lst);
     }
     for (int i = 0; i < step; i++)
     {
         lst.Last().Add(-1);
     }
     lst.Last().Add(n.value);
     lst.Add(new List <int>());
     if (n.left != null)
     {
         print_tree(n.left, step + 1, lst);
     }
 }
Esempio n. 4
0
 RBNode Insert(RBNode rt, RBNode node)
 {
     if (rt == null)
     {
         return(node);
     }
     if (node.value < rt.value)
     {
         rt.left        = Insert(rt.left, node);
         rt.left.parent = rt;
     }
     else
     {
         rt.right        = Insert(rt.right, node);
         rt.right.parent = rt;
     }
     return(rt);
 }
Esempio n. 5
0
        public void rotLeft(ref RBNode rt, RBNode q)
        {
            var piv = q.right;

            if (q.right != null)
            {
                q.right.parent = q;
            }
            piv.parent = q.parent;
            if (q.parent == null)
            {
                rt = piv;
            }
            else if (q == q.parent.left)
            {
                q.parent.left = piv;
            }
            else
            {
                q.parent.right = piv;
            }
            piv.left = q;
            q.parent = piv;
        }