Your best bet is probably a graphical algorithms newsgroup. Seriously.
The C and C++ languages have little to do with your question, since
every implementor that bothers to supply a graphics library at all
tends to supply their own, so any answer here (or anywhere!) is bound
to be platform-specific.
But a graphical algorithms newsgroup will probably know roughly what
you're trying to achieve and will know how to help you achieve it.
But here's a suggestion anyway, to be going on with:
1) decide how much vertical and horizontal space you want (pixels) per
data element (dh, dw), and how much space you want between them (sh,
sw).
2) find out how many rows R you have (how long is your longest path to
a leaf node).
3) calculate H = (R + 1) * (dh + sh).
3) find out how many elements E you have in your last row.
4) calculate W = (E + 1) * (dw + sw);
5) create a canvas H * W pixels wide.
6) draw your first element. The easiest way, by the way, is to use a
rectangle, since the corners are easier to find than an arbitrary
edge point on a circle.
7) recurse into left and right subtrees. For each node you find, you
will need to know whether it's a left child or a right child, so that
you can tell which corner of its surrounding rectangle to join to
which corner of the parent rectangle. I foresee a goodly number of
parameters in your recursive function!
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
Yes. What you can do is add a function to your binary tree code to spit out a
printed representation of the tree in a special markup format which is
understood by diagramming software.
Without endorsing any particular software, one possibility is:
http://www.graphviz.org/
Would a text-based depiction do? (That is, of a binary search tree.)
If so, see Chapter 7 of:
http://www.jgcampbell.com/adsgp/adsgp.pdf
where there there is text-based binary search tree display code copied
from a version in Lafore's Java Data Structures book
Jon C.
--
Jonathan Campbell www.jgcampbell.com BT48, UK.
If the goal is to have the job done, graphviz is also what I would
suggest to use. Won't be a "live" representation, but it may not have
to be. (And it does not mean it cannot be interactive, graphviz does
have support for creating mapping for interactivity for the graphics
files it can produce.)
BR, WW