Are you required to display the tree like that? Because if not, it's much easier to rotate the tree by 90 degrees:
public void TreeStructure(Node root)
{
TreeStructure(root, 0);
}
private void TreeStructure(Node root, int depth)
{
if (root == null) {
for (int i = 0; i < depth; i++)
Console.Write('\t');
Console.WriteLine('~'); // I use ~ to mean null
}
else {
TreeStructure(root.Right_Child, depth + 1);
for (int i = 0; i < depth; i++)
Console.Write('\t');
Console.WriteLine(root.Node_Data);
TreeStructure(root.Left_Child, depth + 1);
}
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Bummer. There's no function I'm aware of that does this for you; you'll have to work out the distances between nodes manually and basically draw the tree as if the console were a GUI.
I'd suggest searching google for people who've already done this and outlined the steps.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401