/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
class Solution {
public:
vector<int>preRet;
vector<int>inRet;
vector<int>postRet;
/**
*
* @param root TreeNode类 the root of binary tree
* @return int整型vector<vector<>>
*/
void preorder(TreeNode* root) {
if (!root) {
return;
}
preRet.push_back(root->val);
preorder(root->left);
preorder(root->right);
}
void inorder(TreeNode* root) {
if (!root) {
return;
}
inorder(root->left);
inRet.push_back(root->val);
inorder(root->right);
}
void postorder(TreeNode* root) {
if (!root) {
return;
}
postorder(root->left);
postorder(root->right);
postRet.push_back(root->val);
}
vector<vector<int> > threeOrders(TreeNode* root) {
preorder(root);
inorder(root);
postorder(root);
cout << preRet.size() << endl;
for (auto n : preRet) {
cout << n << endl;
}
vector<vector<int>> ret (3, vector<int>(preRet.size(), 0));
ret[0] = preRet;
ret[1] = inRet;
ret[2] = postRet;
return ret;
// write code here
}
};