I looked up this basic format for a tree structure in javascript:
function Tree(parent, child, data) {
this.parent = parent;
this.children = child || [];
this.data = data;
this.addNode ...
this.addChild ...
}
the problem I have is making a tree that is "long" with this. The data I'm using is a list of streets on a trail that is almost one straight path, but there are a couple of small splits in the trail, the data would look something like:
A ->
B ->
C ->
D -> E,F
E ->
G ->
H
F -> I
I -> J
J -> K,L
K ->
M ->
N
L -> O
O -> P
I'd like to avoid code that looks like:
tree.children[0].children[0].children[0].addNode("E");
tree.children[0].children[0].children[0].push("F");
so one of my questions is how to traverse the tree, simply by saying?
node = tree;
while(node.children != null)
node = node.children[0];
if you could help me out, I'd appreciate it, thanks,
mathacka