public void Traverse(TraversalType traversalType, TrieVisitor visitor) { if (traversalType == TraversalType.InOrder) { throw new NotImplementedException("InOrder traversal not implemented yet."); } InternalTraverse(rootNode, traversalType, visitor); }
private void InternalTraverse(Node node, TraversalType traversalType, TrieVisitor visitor) { if (traversalType == TraversalType.PreOrder && node.IsLeaf) { visitor.Visit(node); } char[] sortedChildrenKeys = node.Children.Keys.ToArray(); Array.Sort(sortedChildrenKeys); foreach (char c in sortedChildrenKeys) { Node childNode = node.Children[c]; InternalTraverse(childNode, traversalType, visitor); } if (traversalType == TraversalType.PostOrder && node.IsLeaf) { visitor.Visit(node); } }