private ForestNode <E> Next() { if (_current == null) { _current = _root.NewEdge(ForestNode <E> .Edge.Leading); return(_current); } if (_current.CurrentEdge == ForestNode <E> .Edge.Leading) { if (_current.ChildCount == 0) { _current = _current.NewEdge(ForestNode <E> .Edge.Trailing); return(_current); } _current = _current.Child(ForestNode <E> .Edge.Leading, 0); return(_current); } ForestNode <E> parent = _current.Parent(ForestNode <E> .Edge.Trailing); if (parent == null) { throw new Exception("No next node, never reached here"); } int curIndex = _current.ChildIndex; if (curIndex == -1) { throw new Exception("orphan node, invalid"); } if (curIndex < parent.ChildCount - 1) { _current = parent.Child(ForestNode <E> .Edge.Leading, curIndex + 1); return(_current); } // last sibling, go up ward. _current = parent; return(_current); }
public void SkipChildren() { _current = _current.NewEdge(ForestNode <E> .Edge.Trailing); }