Beispiel #1
0
 public BinaryTree(T value, BinaryTree <T> parent)
 {
     this.value  = value;
     this.parent = parent;
 }
Beispiel #2
0
 public BinaryTree(BinaryTree <T> parent)
 {
     this.parent = parent;
 }
Beispiel #3
0
 public BinaryTree(BinaryTree <T> left, BinaryTree <T> right)
 {
     this.Left  = left;
     this.Right = right;
 }
Beispiel #4
0
        public BinaryTree <T> GetNextLeaf(Func <BinaryTree <T>, bool> comparer, Direction direction, BinaryTree <T> relation = null)
        {
            if (relation == null)
            {
                if (Parent != null)
                {
                    return(Parent.GetNextLeaf(comparer, direction, this));
                }
            }
            else
            {
                if (Left == relation && direction == Direction.ToRight)
                {
                    if (comparer(this))
                    {
                        return(this);
                    }
                    if (Right != null)
                    {
                        var r = Right.FindFirst(comparer, direction);
                        if (r != null)
                        {
                            return(r);
                        }
                    }
                }
                if (Right == relation && direction == Direction.ToLeft)
                {
                    if (comparer(this))
                    {
                        return(this);
                    }
                    if (Left != null)
                    {
                        var l = Left.FindFirst(comparer, direction);
                        if (l != null)
                        {
                            return(l);
                        }
                    }
                }
                if (Parent != null)
                {
                    return(Parent.GetNextLeaf(comparer, direction, this));
                }
            }

            return(null);
        }
Beispiel #5
0
 public BinaryTree(T left, T right)
 {
     this.left  = new BinaryTree <T>(left, this);
     this.right = new BinaryTree <T>(right, this);
 }