Using the BTree package at SqueakSource (or any other you may know) and given the following tree
-Root
|
--Node1
|
--Node2
---Node21
---Node22
---Node23
----Node231
----Node232
-----Node2321
----Node233
|
--Node3
I’ve tried to write the following but without success:
- Build the tree
- Given Node23 answer its direct children
- Given Node2 answer all its children
- Given any Node, answer its parent
- Collect all the children
This is NOT homework, the reason why I’m asking for a basic example is because in the case of BTree, documentation is almost inexistent, and tests are not good enough for figuring out basic usage, actually examples are mixed with asserts and using convenience methods.
If you’re not so concerned with execution speed, there is an extensively documented package in SqueakSource for that purpose http://www.squeaksource.com/TreeLW.html which was originally released for VisualWorks.
One class you may use for building your tree is SKPVTreeLW, which supports value, subtrees, supertree, and a key. You may achieve your example implementing something like this: