Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

can anyone help me in graphics in C++

0 views
Skip to first unread message

NSS GRG

unread,
Nov 9, 2009, 10:13:03 PM11/9/09
to
hello frens,
I want to graphically represent data of an array in a binary tree
graphically. Can anyone help me?

Richard Heathfield

unread,
Nov 9, 2009, 10:49:13 PM11/9/09
to
In
<3b3285fd-68e9-4db6...@m16g2000yqc.googlegroups.com>,
NSS GRG wrote:

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

Kaz Kylheku

unread,
Nov 10, 2009, 1:03:09 PM11/10/09
to

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/

Jonathan Campbell

unread,
Nov 11, 2009, 8:37:37 AM11/11/09
to

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.

White Wolf

unread,
Nov 20, 2009, 8:03:56 PM11/20/09
to

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

0 new messages