二叉树的中序、前序、后序遍历

给定一个二叉树的根节点 root ,返回它的 中序 前序  后序遍历:

var orderTraversal = function(root){
    const res = [];
    const order = (root)=>{
        if(root!=null){
            // res.push(root.val); 前序
            order(root.left);
            // res.push(root.val); 中序
            order(root.right); 
            // res.push(root.val); 后序
        }
    }
    order(root);
    return res;
}

 

 




posted on 2021-06-14 23:03  BillGates--  阅读(66)  评论(0)    收藏  举报