/**
* 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>pre,in,post;
void preOrder(TreeNode* root) {
// 中左右
if (!root) {
return;
}
pre.push_back(root->val);
preOrder(root->left);
preOrder(root->right);
}
void inOrder(TreeNode* root) {
// 中左右
if (!root) {
return;
}
inOrder(root->left);
in.push_back(root->val);
inOrder(root->right);
}
void postOrder(TreeNode* root) {
// 中左右
if (!root) {
return;
}
postOrder(root->left);
postOrder(root->right);
post.push_back(root->val);
}
vector<vector<int> > threeOrders(TreeNode* root) {
vector<vector<int>>ret;
// 前序遍历
preOrder(root);
// 中序遍历
inOrder(root);
// 后序遍历
postOrder(root);
ret.push_back(pre);
ret.push_back(in);
ret.push_back(post);
return ret;
}
};