Simple Tree
I found this bit of code amongst my collection of code-snippets. It's a fairly simple program that reads a tree from a file and "pretty-prints" it to stdout.
For example, given this input file:
|blue
|green
green|yellow
yellow|red
Would result in this tree:
blue
green
yellow
red
It's implemented via an N-ary tree, without the restriction that each node must have N children. The only restriction is that the value of a node must be unique.
I've used variants of this in a number of places, handy for ensuring a tree as stored in memory matches what I think it should.
Feel free to download it and reuse it.
Tags
Revisions
-
1/4/2006 - Article published.