Your skill will accomplishwhat the force of many cannot PerlMonks

### Dumping trees to a console.

by BrowserUk (Pope)
 on Oct 15, 2012 at 14:11 UTC ( #999091=CUFP: print w/replies, xml ) Need Help??

Dumping trees to a terminal in a compact, readable form is an invaluable aid to developing and debugging tree-based algorithms. The following demonstrates a mechanism for doing this for array-based binary trees:

A couple of examples:

```C:\test>genBinTree -S=1
___________
___________/           \___
_______/           \_         _/   \
_____/       \_         _/ \_     _/ \_  z
_/     \_     _/ \_     _/ \ / \  _/ \ / \
_/ \_   _/ \  _/ \ / \  _/ \ r s t / \ w x y
_/ \ / \ / \ h / \ k m n / \ q       u v
/ \ c d e f g   i j       o p
a b

C:\test>genBinTree -S=1 -N
___________
___________/           \___
_______/           \_         _/   \
_____/       \_         _/ \_     _/ \_  z
_/     \_     _/ \_     _/ \ / \  _/ \ / \
_/ \_   _/ \  _/ \ / \  _/ \ r s t / \ w x y
_/ \ / \ / \ h / \ k m n / \ q       u v
/ \ c d e f g   i j       o p
a b

a b c d e f g h i j k m n o p q r s t u v w x y z
l r h e c o o o n u i i o s a u o i a n i h r a u
p a a l h x l t d l l k v c p e m e n i c i a n l
h v r t o t f e i i o e e a a b e r g f t s y k u
a o l a   r   l g e     m r   e o r o o o k   e
i     o     o t     b     c   a   r r e   e
e     t             e             m   y
r

C:\test>genBinTree -S=1234567890123456789
_____________________
_______/                     \_
_______/       \___________         _/ \___
_/       \  _____/           \      _/ \ /   \_
/ \___    f /     \_________  q    _/ \ v w  _/ \
a /   \_    g  ___/         \    _/ \ u     / \ z
b  _/ \     /   \_____    p   / \ t       x y
/ \ e     h  _/     \_      r s
c d         / \_   _/ \
i / \ / \ o
j k m n

C:\test>genBinTree -S=123456789012345678
_______
___/       \_
_/   \_     _/ \_______
/ \_  / \_  / \ /       \_________
a / \ d / \ g h i      _/         \___________
b c   e f          _/ \      ___/           \_
_/ \ n    _/   \      _____/ \
/ \ m    _/ \_  s  ___/     \ z
j k     / \ / \   /   \_    y
o p q r   t  _/ \_
/ \ / \
u v w x

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Create A New User
Node Status?
node history
Node Type: CUFP [id://999091]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2016-10-24 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many different varieties (color, size, etc) of socks do you have in your sock drawer?

Results (303 votes). Check out past polls.