Tree: Preorder Traversal

  • + 0 comments

    JavaScript solution using recursion

    function preOrder(root) {
        let res = '';
        function abc(root){
          if(root){
            res = res + root.data + '  ';
            abc(root.left);
            abc(root.right)  
           }
        }
        abc(root);
        console.log(res)
    }