private void PrintTree(Node root, string pre) { LoopTraverse traverse = new LoopTraverse(); var inValues = traverse.In(root).Select(x => x.V).ToArray(); Console.WriteLine("{0}{1}", pre, string.Join(",", inValues)); }
public void Run() { var root = BuildTree(); Console.WriteLine("Recursive: "); RecurTraverse recurTraverse = new RecurTraverse(); IEnumerable <Node> nodes = recurTraverse.Pre(root); PrintNodes(nodes, "Pre"); nodes = recurTraverse.In(root); PrintNodes(nodes, "In"); nodes = recurTraverse.Post(root); PrintNodes(nodes, "Post"); Console.WriteLine("Loop: "); LoopTraverse loopTraverse = new LoopTraverse(); nodes = loopTraverse.PreWithSimple(root); PrintNodes(nodes, "PreWithSimple"); nodes = loopTraverse.PreWithState(root); PrintNodes(nodes, "PreWithState"); nodes = loopTraverse.Pre(root); PrintNodes(nodes, "Pre"); nodes = loopTraverse.PreWithMorris(root); PrintNodes(nodes, "PreWithMorris"); nodes = loopTraverse.InWithState(root); PrintNodes(nodes, "InWithState"); nodes = loopTraverse.In(root); PrintNodes(nodes, "In"); nodes = loopTraverse.InWithMorris(root); PrintNodes(nodes, "InWithMorris"); nodes = loopTraverse.PostWithState(root); PrintNodes(nodes, "PostWithState"); nodes = loopTraverse.Post(root); PrintNodes(nodes, "Post"); nodes = loopTraverse.PostWithMorris(root); PrintNodes(nodes, "PostWithMorris"); nodes = loopTraverse.Row(root); PrintNodes(nodes, "Row"); var nodesList = loopTraverse.RowList(root); PrintNodes(nodesList, "RowList"); nodesList = loopTraverse.ColumnList(root); PrintNodes(nodesList, "ColumnList"); }