Iterative

var count = function(tree) {
    stack = [ tree ];
    c = 0;
    while (stack.length > 0) {
        node = stack.pop();
        if (node !== null) {
            c += 1;
            stack.push(node.left);
            stack.push(node.right);
        }
    }
    return c;
};



Casiano Rodriguez León 2015-01-07