예제 #1
0
        private bool TraverseRight()
        {
            _breadcrumb.Push(_current);
            _current = _current.RightChild;

            return(true);
        }
예제 #2
0
 public bool MoveNext()
 {
     if (_current == null)
     {
         Reset();
         _current = _tree;
         _enumerators.Enqueue(_current.Children().GetEnumerator());
         return(true);
     }
     while (_enumerators.Count > 0)
     {
         var enumerator = _enumerators.Peek();
         if (enumerator.MoveNext())
         {
             _current = enumerator.Current;
             _enumerators.Enqueue(_current.Children().GetEnumerator());
             return(true);
         }
         else
         {
             _enumerators.Dequeue();
         }
     }
     return(false);
 }
예제 #3
0
        public bool MoveNext()
        {
            if (_current == null)
            {
                Reset();
                _current = _tree;
                return(true);
            }
            if (_current.LeftChild != null)
            {
                return(TraverseLeft());
            }
            if (_current.RightChild != null)
            {
                return(TraverseRight());
            }

            return(TraverseUpAndRight());
        }
예제 #4
0
 public void Add(T value)
 {
     if (LeftChild == null)
     {
         LeftChild = new DemoTree2 <T>(value);
     }
     else if (RightChild == null)
     {
         RightChild = new DemoTree2 <T>(value);
     }
     else if (LeftChild.Depth() < RightChild.Depth())
     {
         LeftChild.Add(value);
     }
     else
     {
         RightChild.Add(value);
     }
 }
예제 #5
0
 private bool TraverseUpAndRight()
 {
     if (_breadcrumb.Count > 0)
     {
         _previous = _current;
         while (true)
         {
             _current = _breadcrumb.Pop();
             if (_previous != _current.RightChild)
             {
                 break;
             }
         }
         if (_current.RightChild != null)
         {
             _breadcrumb.Push(_current);
             _current = _current.RightChild;
             return(true);
         }
     }
     return(false);
 }
예제 #6
0
 public void Reset()
 {
     _current = null;
 }
예제 #7
0
 public DemoTreeEnumerator(DemoTree2 <T> tree)
 {
     _tree = tree;
 }
예제 #8
0
 public void Reset()
 {
     _current = null;
     _enumerators.Clear();
 }
예제 #9
0
 public DemoTreeBreadthFirstEnumerator(DemoTree2 <T> tree)
 {
     _tree = tree;
 }