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

example :
.......10 14.........16 18


my Node class :

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

Recommended Answers

All 3 Replies

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.WriteLine('~'); // I use ~ to mean null
    else {
        TreeStructure(root.Right_Child, depth + 1);

        for (int i = 0; i < depth; i++)


        TreeStructure(root.Left_Child, depth + 1);

Unfortunately the form in which the tree should displayed is required

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.