I was looking for a tree or graph data structure in C# but I guess there isn't one provided. An Extensive Examination of Data Structures Using C# 2.0 explains a bit about why. Is there a convenient library which is commonly used to provide this functionality? Perhaps through a strategy pattern to solve the issues presented in the article.
I feel a bit silly implementing my own tree, just as I would implementing my own ArrayList.
I just want a generic tree which can be unbalanced. Think of a directory tree. C5 looks nifty, but their tree structures seem to be implemented as balanced red-black trees better suited to search than representing a hierarchy of nodes.
I have added complete solution and example using NTree class above, also added "AddChild" method...
using
I have a little extension to the solutions.
Using a recursive generic declaration and a deriving subclass you can better concentrate on your actual target.
Notice, it's different from a non generic implementation, you don`t need to cast 'node' in 'NodeWorker'.
Here's my example: