Ha! No this isn’t a zen exercise in focusing the mind. With my new blog I thought I’d refactor my binary search tree code. This post includes the page for my binary search tree code and the description.
Since the last time I looked on Wikipedia for Binary Search Tree information it seems there have been some very decent updates. My refactored code has both iterative and recursive versions of pre-order, in-order, and post-order traversal methods. I used the Wikipedia traversal pseudo code as a model for my methods.
This first link is general information about binary search tress.
The second link is specifically about traversing trees.
I used the information on Bill Mill’s site for displaying the tree view, specifically Donald Knuth’s algorithm.
I provided a text field to enter an integer value as a node value. Adding successive values will build the tree and update its properties. Clicking the “Add Node” button or just pressing enter will add the new node to the tree. Of course the “Reset” button clears the tree. In any event have a look at the code if you like. There is a good bit of code there and it could stand to be cleaned up which I may get around to but maybe this may be of help to someone.
Update: I recently had a request to make the source code available via GitHub. You can now access the source code via the following link.