void traverse(TreeNode* root) { if (!root) return; traverse(root->left); traverse(root->right); cout << root->val << " "; }
前序遍历
中序遍历
后序遍历
层序遍历