- 递归形式的先序、中序、后序 + 非递归层次遍历:
//树的数据结构
function TreeNode(x){
this.val = x;
this.left = null;
this.right = null;
}
//先序遍历(Degree Left Right)
function DLR(root){
console.log(root.val);
if(root.left){
DLR(root.left);
}
if(root.right){
DLR(root.right);
}