Display Binary Search Tree Traversal on Javascript (Recursive way)
<p>I am trying to console every data in a binary tree. My main problem is that I want to implementing in a recursive way. Basically I have this code so far:</p>

<pre><code>this.levelOrder = function (root) {
    if (root.data != null) {
        console.log(root.data);

        if (root.left != null) {
            this.levelOrder(root.left);
        }

        if (root.right != null) {
            this.levelOrder(root.right)
        }
    } else {
        return;
    }
};
</code></pre>

<p>The output is <code>3 2 1 5 4 7</code></p>

<p>But It should be <code>3 2 5 1 4 7</code>. So Basically I am accessing the first child of the node instead of printing all the children first.</p>