function TreeNode(val, left, right) {
this.val = val;
this.left = left;
this.right = right;
}
var printBefore = function (list, node) {
if (!node) {
return;
}
list.push(node.val);
printBefore(list, node.left);
printBefore(list, node.right);
}
var printCenter = function (list, node) {
if (!node) {
return;
}
printCenter(list, node.left);
list.push(node.val);
printCenter(list, node.right);
}
var printAfter = function (list, node) {
if (!node) {
return;
}
printAfter(list, node.left);
printAfter(list, node.right);
list.push(node.val);
}
var preorderTraversal = function (root) {
let list = [];
printBefore(list, root)
printCenter(list, root)
printAfter(list, root)
return list
};