function TreeNode(val) {
this.val = val;
this.left = this.right = null;
}
function buildTree(arr) {
if (!arr) return [];
const root = new TreeNode(arr[0]);
const q = [root];
let index = 0;
while (index < arr.length) {
let cur = q.shift();
console.log(q)
index++;
if (index < arr.length && arr[index]) {
cur.left = new TreeNode(arr[index]);
q.push(cur.left);
}
index++;
if (index < arr.length && arr[index]) {
cur.right = new TreeNode(arr[index]);
q.push(cur.right);
}
console.log(cur.left)
}
return root;
}
function pre(root) {
if (!root) return root;
console.log(root.val);
pre(root.left);
pre(root.right);
}
function mid(root) {
if (!root) return root;
mid(root.left);
console.log(root.val);
mid(root.right);
}
const root = buildTree([1, 2, 3, 4, null, null, 7]);
pre(root);
mid(root);
console