Tree: Postorder Traversal

  • + 0 comments

    Javascript:

    function postOrder(root) {
    	  let result = []
    		let values = ""
        
        function dfsPostTraverse(currentNode){
            if(currentNode == null){
                return;
            }
            dfsPostTraverse(currentNode.left)
            dfsPostTraverse(currentNode.right)
            result.push(currentNode.data)
        }
        
        dfsPostTraverse(root)
        
        for(let i=0; i<result.length; i++){
            values += result[i] + " "
        }
        console.log(values)
    }