function treeforeach_rec(tree, node_id, fun) {

    // Execute fun on all nodes of the subtree tree[node_id]
    
    var a, b, node = tree[node_id];
    
    // Breadth
    fun(tree, node_id);
    
    // Depth
    for (b = 0; b < node.children.length; b++) {
        treeforeach_rec(tree, node.children[b], fun);
    }
}

