A java package for visualizing binary trees in ASCII text. Only the abstract superclass TreeGraphics, and concrete subclasses NullTreeGraphics and ASCIITreeGraphics have been ported from the Pascal source developed for Brown University Computer Science 16.
The TreeGraphics routines work by getting from you a pre-order traversal of your tree, in terms of calls to DrawInternal and DrawLeaf. The exact semantics of these calls are
DrawInternal(String nodeLabel); DrawLeaf();
For example:
39 .------------------------------------+------------------------------------. | | | | 25 45 .-----------------+-----------------. .-----------------+-----------------. | | | | | | | | 19 35 [_] 51 .--------+--------. .--------+--------. .--------+--------. | | | | | | | | | | | | 13 [_] [_] 38 [_] [_] .---+---. .---+---. | | | | | | | | [_] [_] [_] [_]
Remember that TreeGraphics needs the calls in pre-order (root-left-right), so the sequence of calls to create this tree would have been the following:
DrawInternal("39"); DrawInternal("25"); DrawInternal("19"); DrawInternal("13"); DrawLeaf(); DrawLeaf(); DrawLeaf(); DrawInternal("35"); DrawLeaf(); DrawInternal("38"); DrawLeaf(); DrawLeaf(); DrawInternal("45"); DrawLeaf(); DrawInternal("51"); DrawLeaf(); DrawLeaf();