Implementation of Binary Trees

Status
Not open for further replies.

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
code:<HR>
Code:
stuff DoStuff (node * myNode)
{
  stuff null_case, other_case;
  if (myNode == NULL)
    return null_case;
  DoStuff(myNode->left);
  DoStuff(myNode->right);
  return other_case;
}
That's horribly mangled C++, but transfering it to a useful VB function shouldn't be hard. Point being, recursion is your friend with tree-like data structures.
 

kleel

Ars Scholae Palatinae
1,022
dunno, maybe a class (called TreeNode) with a data property (for your data), a leftNode property of type TreeNode and a rightNode property of type TreeNode.

You could then use the above class in a BinTree class that would have a few "add node" methods and "traversal" methods to keep everthing nice and tidy.

I implemented a linked list strucure in vb using a method similar to the above. You may have to implement interfaces to the class to do it right though.

I'll have to dig the code up ..

Kleel
 
Status
Not open for further replies.