Preorder\u3001inorder\u3001postorder iterative solution by c++
preorder:\n\n    vector preorderTraversal(TreeNode root) {\n    \tvector res;\n    \tstd::stack temp;\n    \twhile (root || !temp.empty()) {\n    \t\twhile (roo
preorder:\n\n    vector<int> preorderTraversal(TreeNode* root) {\n    \tvector<int> res;\n    \tstd::stack<TreeNode*> temp;\n    \twhile (root || !temp.empty()) {\n    \t\twhile (root) {\n    \t\t\ttemp.push(root);\n    \t\t\tres.push_back(root->val);\n    \t\t\troot = root->left;\n    \t\t}\n    \t\troot = temp.top();\n    \t\ttemp.pop();\n    \t\troot = root->right;\n    \t}\n    \treturn res;\n    }\ninorder:\n\n    vector<int> inorderTraversal(TreeNode* root) {\n    \tvector<int> res;\n    \tstd::stack<TreeNode*> temp;\n    \twhile (root || !temp.empty()) {\n    \t\twhile (root) {\n    \t\t\ttemp.push(root);\n    \t\t\troot = root->left;\n    \t\t}\n    \t\troot = temp.top();\n    \t\ttemp.pop();\n    \t\tres.push_back(root->val);\n    \t\troot = root->right;\n    \t}\n    \treturn res;\n    }\n\npostorder:\n\n    vector<int> postorderTraversal(TreeNode* root) {\n    \tvector<int> res;\n    \tstd::stack<TreeNode*> temp;\n    \twhile (root || !temp.empty()) {\n    \t\twhile (root) {\n    \t\t\ttemp.push(root);\n    \t\t\tres.insert(res.begin(),root->val);\n    \t\t\troot = root->right;\n    \t\t}\n    \t\troot = temp.top();\n    \t\ttemp.pop();\n    \t\troot = root->left;\n    \t}\n    \treturn res;\n    }
[]