Ejemplo n.º 1
0
        private void InsertRec(DTOTree root, DTOTree newNode)
        {
            if (root == null)
            {
                root = newNode;
            }

            if (newNode.data < root.data)
            {
                if (root.Left == null)
                {
                    root.Left = newNode;
                }
                else
                {
                    InsertRec(root.Left, newNode);
                }
            }
            else
            {
                if (root.Right == null)
                {
                    root.Right = newNode;
                }
                else
                {
                    InsertRec(root.Right, newNode);
                }
            }
        }
Ejemplo n.º 2
0
 public void Insert(int data)
 {
     if (_root == null)
     {
         _root = new DTOTree(data);
         return;
     }
     InsertRec(_root, new DTOTree(data));
     //throw new NotImplementedException();
 }
Ejemplo n.º 3
0
        private void print(DTOTree root, String prefix)
        {
            if (root == null)
            {
                Console.Write(prefix + "+- <null>");
                return;
            }

            Console.Write(prefix + "+- " + root.data);
            print(root.Left, prefix + "|  ");
            print(root.Right, prefix + "|  ");
        }
Ejemplo n.º 4
0
 public int ClosestCommonAncestor(DTOTree searchTree, int a, int b)
 {
     if (searchTree == null)
     {
         return(-1);
     }
     if (searchTree.data.CompareTo(a) > 0 && searchTree.data.CompareTo(b) > 0)
     {
         return(ClosestCommonAncestor(searchTree.Left, a, b));
     }
     if (searchTree.data.CompareTo(a) < 0 && searchTree.data.CompareTo(b) < 0)
     {
         return(ClosestCommonAncestor(searchTree.Right, a, b));
     }
     return(searchTree.data);
 }
Ejemplo n.º 5
0
 public NodeTreeBll()
 {
     _root = null;
 }
 public int AncestroComun(DTOTree tree, int a, int b)
 {
     //_nodeTreeBll.ClosestCommonAncestor(a, b);
     return(_nodeTreeBll.ClosestCommonAncestor(tree, a, b));
 }