-
Notifications
You must be signed in to change notification settings - Fork 0
DFS in TREE
Rayhan Uddin edited this page Jun 2, 2017
·
2 revisions
Tree.prototype.traverse = function (callback) {
var stack=[this];
var n;
while(stack.length>0) {
n = stack.pop();
callback(n.value);
if (!n.children) {
continue;
}
for (var i = n.children.length-1; i>=0; i--) {
stack.push(n.children[i]);
}
}
};