Using C#, I have created a "node" class (which contains a List
of type itself) to allow for recursive tree-like data structures. This is a simplified version of the class:
public class node
{
public List<node> c = null;
public int data = 0;
public node(int data)
{
this.data = data;
}
}
Unfortunately, I've come across a point in my program where it's getting very hard to debug due to the nature of trees. Large trees especially are difficult to probe visually.
For this reason, I had the brain wave to use Winform's TreeView
control to display the data so I can more easily visualize what's going on. I understand and have implemented preorder and inorder traversal for a minimax algorithm, and so I was wondering if I could utilize some of that code to help with converting from my own node tree to a TreeView
tree.
The method skeleton would look like this:
private void convertNodetreetoTreeview(node n)
{
TreeNode root = new TreeNode("Root node");
...
treeView1.Nodes.Add(root);
}
How would I go about this?
For speed, I would prefer an iterative solution, but a recursive solution would be fine too.