Example #1
0
 public BinaryTreeBaseNode(T value, BinaryTreeBaseNode <T> left, BinaryTreeBaseNode <T> right, BinaryTreeBaseNode <T> parent = null)
 {
     Parent = parent;
     Left   = left;
     Right  = right;
     Value  = value;
 }
Example #2
0
        public IEnumerator PreorderTraversal()
        {
            Stack <BinaryTreeBaseNode <T> > traversalStack = new Stack <BinaryTreeBaseNode <T> >();
            BinaryTreeBaseNode <T>          nowTraveling   = this;

            traversalStack.Push(nowTraveling);
            while (traversalStack.Count != 0)
            {
                while (nowTraveling != null)
                {
                    traversalStack.Push(nowTraveling);
                    yield return(nowTraveling);

                    nowTraveling = nowTraveling.Left;
                }
                nowTraveling = traversalStack.Pop().Right;
            }
        }
Example #3
0
        public IEnumerator <object> BreadthFirst()
        {
            Queue <BinaryTreeBaseNode <T> > traveralQueue = new Queue <BinaryTreeBaseNode <T> >();

            traveralQueue.Enqueue(this);

            while (traveralQueue.Count != 0)
            {
                BinaryTreeBaseNode <T> node = traveralQueue.Dequeue();
                yield return(node);

                if (node.Left != null)
                {
                    traveralQueue.Enqueue(node.Left);
                }
                if (node.Right != null)
                {
                    traveralQueue.Enqueue(node.Right);
                }
            }
        }
Example #4
0
 public BinaryTreeRootNode(T value, BinaryTreeBaseNode <T> left, BinaryTreeBaseNode <T> right, BinaryTreeBaseNode <T> parent = null)
     : base(value, left, right, parent)
 {
 }