View Full Version : FAQ Printing a binary tree?? (C)
Unregistered
10-31-2001, 12:21 PM
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....
Salem
10-31-2001, 12:39 PM
> 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.
Unregistered
10-31-2001, 12:43 PM
I want a graphically output:
example:
100
50
40
25 30
12
......and such
Unregistered
10-31-2001, 12:45 PM
that didnt come out right....cuz I guess this forum doesnt display the spaces. I want a graphically tree with the corresponding numbers.
Unregistered
10-31-2001, 04:31 PM
i still need some help???what this printing of a tree structure.....
QuestionC
10-31-2001, 07:35 PM
Still not too sure what your asking, but here goes...
1) The generic treeprinting programvoid printtree(node * tree)
{
if (tree != NULL)
{
print (tree -> info); // Not a real command
printtree (tree -> left);
printtree (tree -> right);
}
}2) 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.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.