Hello all,
I have written a pretty simple tree data structure that implements the IEnumerable interface.
Everything is working great, I'm adding my nodes and the data is actually an object, so to create a node in my tree, I use something like this:
After adding the top level tree, adding children to the tree is as simple as using tree.AddChild(root, QNode)
So now that I have my tree, if I want to iterate through them. If I use a simple Print method and iterate through the nodes:
What I really want to do, is expose the methods and properties as I iterate through the node. For example, if I wanted to expose QNode.Name for each iteration, but I can't quite get the logic right in my head to do the implementation. Is it a change to the enumerate implementation? (private IEnumerable<T> enumerate(Node<T> root) or is it a change to the print method?
Thanks for your help, hopefully my question is clear enough!
Regards
DJ
I have written a pretty simple tree data structure that implements the IEnumerable interface.
C#:
class Tree<T> : IEnumerable<T>
Everything is working great, I'm adding my nodes and the data is actually an object, so to create a node in my tree, I use something like this:
C#:
var tree = new Tree<QNode>();
After adding the top level tree, adding children to the tree is as simple as using tree.AddChild(root, QNode)
So now that I have my tree, if I want to iterate through them. If I use a simple Print method and iterate through the nodes:
C#:
public static void Print(this object self)
{
Console.WriteLine(self);
}
What I really want to do, is expose the methods and properties as I iterate through the node. For example, if I wanted to expose QNode.Name for each iteration, but I can't quite get the logic right in my head to do the implementation. Is it a change to the enumerate implementation? (private IEnumerable<T> enumerate(Node<T> root) or is it a change to the print method?
Thanks for your help, hopefully my question is clear enough!
Regards
DJ