PHP4 Compatible Object Oriented Binary Tree (Naive)
What am I?
A binary tree with a simple set of operations and a test script. The set of operations is the most basic you need - with some mild duplication (deleteNode). This tree uses recursion, so it may not be that great on large trees. Delete is simple (naive) - it deletes all children recursively, then the node in question. This could probably be cleaner with some quick mods to the source.
You may note that the tree node doesn't store its parent, and that I chose to define this recursively.
Huh? Why
To keep myself from getting rusty, to use recursion (yeah... not that common in what I get paid to do recently) and because startlingly enough there doesn't seem to be one. Go no. Of course, you can always write one using arrays, or associative arrays (or, hashtables as some like to refer to them).
Notes
There are a couple functions that should be private, but there is no protection in PHP4 for such matters. I also made a BTreeNode so you could subclass it.
This page is
CategoryMiscProjects
There are no comments on this page. [Add comment]