```
//use a stack
//stack pop order:root,right,left
//reverse the result
class Solution {
public:
vector<int> postorderTraversal(TreeNode* root) {
vector<int> res;
stack<TreeNode*> tree;
TreeNode* tmp;
if(!root)
return res;
tree.push(root);
while(!tree.empty()){
tmp=tree.top();
tree.pop();
res.push_back(tmp->val);
if(tmp->left)
tree.push(tmp->left);
if(tmp->right)
tree.push(tmp->right);
}
reverse(res.begin(),res.end());
return res;
}
};
```