# 实现二叉树先序，中序和后序

{1,2,3}

[[1,2,3],[2,1,3],[2,3,1]]

/**
* struct TreeNode {
*	int val;
*	struct TreeNode *left;
*	struct TreeNode *right;
* };
*/

class Solution {
public:
/**
*
* @param root TreeNode类 the root of binary tree
* @return int整型vector<vector<>>
*/
vector<int> preOrder(TreeNode* root)
{
vector<int> res;
if (root == NULL) return res;
else{
res.push_back(root->val);
for (auto v: preOrder(root->left))
res.push_back(v);
for (auto v: preOrder(root->right))
res.push_back(v);
}
}

vector<int> midOrder(TreeNode* root)
{
vector<int> res;
if (root == NULL) return res;
else{
for (auto v: preOrder(root->left))
res.push_back(v);
res.push_back(root->val);
for (auto v: preOrder(root->right))
res.push_back(v);
}
}

vector<int> postOrder(TreeNode* root)
{
vector<int> res;
if (root == NULL) return res;
else{
for (auto v: preOrder(root->left))
res.push_back(v);
for (auto v: preOrder(root->right))
res.push_back(v);
res.push_back(root->val);
}
}

vector<vector<int> > threeOrders(TreeNode* root) {
// write code here
vector<int> pre = preOrder(root);
vector<int> mid = midOrder(root);
vector<int> post = postOrder(root);

vector<vector<int>> res;
res.push_back(pre);
res.push_back(mid);
res.push_back(post);
return res;
}
};

06-01

07-17
11-02
05-14 370
10-10 1万+
11-16 2万+
06-08 10万+