二叉树的前序、中序、后序遍历
class Solution {
public:
vector<vector<int> > threeOrders(TreeNode* root) {
vector<int> preOrder;
vector<int> inOrder;
vector<int> postOrder;
pre_in_post_order(root,preOrder,inOrder,postOrder);
vector<vector<int>> result = {preOrder,inOrder,postOrder};
return result;
}
private:
void pre_in_post_order(TreeNode* root,vector<int>& preOrder,vector<int>& inOrder, vector<int>& postOrder)
{
if(!root) return;
preOrder.push_back(root->val);
pre_in_post_order(root->left,preOrder,inOrder,postOrder);
inOrder.push_back(root->val);
pre_in_post_order(root->right,preOrder,inOrder,postOrder);
postOrder.push_back(root->val);
}
};