I am currently working on a function that accepts the root for a binary tree and prints out the tree structure with the numbers. I want to know where do I begin. Do I need to count the height of the tree or what... I need some help....
Printable View
I am currently working on a function that accepts the root for a binary tree and prints out the tree structure with the numbers. I want to know where do I begin. Do I need to count the height of the tree or what... I need some help....
> I want to know where do I begin.
At the root of the tree :p
> Do I need to count the height of the tree or what
That would depend on how you choose to represent the tree when you've printed it.
If its just a text dump, no formatting is required
But if it's a nice graphical thing, then more work is required.
I want a graphically output:
example:
100
50
40
25 30
12
......and such
that didnt come out right....cuz I guess this forum doesnt display the spaces. I want a graphically tree with the corresponding numbers.
i still need some help???what this printing of a tree structure.....
Still not too sure what your asking, but here goes...
1) The generic treeprinting program2) If you want a graphical tree, might I suggest something using ASCII characters 179, 192, and 195? You know, just do those to draw lines from nodes to their children, with each node being on a different line. It's not spaced out as a tree diagram usually is, but it does have connectivity lines, which is the importatnt thing, personally.Code:void printtree(node * tree)
{
if (tree != NULL)
{
print (tree -> info); // Not a real command
printtree (tree -> left);
printtree (tree -> right);
}
}