>Am I just talking nonsense?
Nope, those are all very good questions.
>do I just construct them as you would a binary tree?
Most likely not if what you're used to are binary search trees. The strict ordering of less than/greater than is what makes binary search trees work, and modifying that to work with three way paths typically results in a multiway tree of order 3 rather than a true tertiary tree. The first thing you need to do is figure out how to order the data so that a simple insertion algorithm can be written.
>Do I just add another child node to the tree to make it have three children?
You add another child link to each node so that the potential number of children increases to three:
class node {
public type data;
public node first, second, third;
}
Or, because it's almost always easier to work with an array of links instead of separate variables:
class node {
public type data;
public node[] link;
}
Of course, variations exist such as an ArrayList or LinkedList. You can even hardcode your own linked list operations if you want.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54