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....
This is a discussion on FAQ Printing a binary tree?? (C) within the FAQ Board forums, part of the General Programming Boards category; I am currently working on a function that accepts the root for a binary tree and prints out the tree ...
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
> 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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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); } }
Callou collei we'll code the way
Of prime numbers and pings!