I looked at 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 to create a tree that is βlongβ with this. The data I use is a list of streets on the trail, which is almost one straight path, but there are a few small gaps in the trail, the data will look something like this:
A -> B -> C -> D -> E,FE -> G -> HF -> II -> JJ -> K,LK -> M -> N L -> O O -> P
I would like to avoid code that looks like this:
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 get through the tree, simply saying:
node = tree; while(node.children != null) node = node.children[0];
If you could help me, I would appreciate it, thanks,
mathacka
source share