How do I print out a tree structure?
http://stackoverflow.com/questions/1649027/how-do-i-print-out-a-tree-structure
多谢熊神给的链接,圆满的解决了我的问题。语法树本来自己写的丑的不忍直视。。现在好看多了,哈哈
其中最短小精悍的是节点中打印连线,很棒。
class Node
{
public string Name;
public decimal Time;
public List Children = new List();
public void PrintNode(string prefix)
{
Console.WriteLine("{0} + {1} : {2}", prefix, this.Name, this.Time);
foreach (Node n in Children)
if (Children.IndexOf(n) == Children.Count - 1)
n.PrintNode(prefix + " ");
else
n.PrintNode(prefix + " |");
}
}
ANd then to print the whole tree just execute:
topNode.PrintNode(“”);
这是C#,都是C嘛。
mark 留念~