1function inorder(root) {
2 if (root === null) return;
3 inorder(root.left); // 递归左子树
4 visit(root); // 访问当前节点
5 inorder(root.right); // 递归右子树
6}
7
8function preorder(root) {
9 if (root === null) return;
10 visit(root); // 访问当前节点
11 preorder(root.left); // 递归左子树
12 preorder(root.right); // 递归右子树
13}
14
15function postorder(root) {
16 if (root === null) return;
17 postorder(root.left); // 递归左子树
18 postorder(root.right); // 递归右子树
19 visit(root); // 访问当前节点
20}