0

Hi,

Does anyone know a function that prints out binary tree in this form

example :
................15
.........12.............17
.......10 14.........16 18


?

my Node class :

class Node
{
 double Node_Data;
 Node Left_Child;
 Node Right_Child;
 Node Parent;
}

Edited by c++_fem: n/a

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Narue
1

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);
    }
}
0

Unfortunately the form in which the tree should displayed is required

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.