c++ iterative post order without reverse or linked list
The idea is to keep track of the last node (traversed and then) popped from the stack. When the last popped node is the last child of current node, it means tha
The idea is to keep track of the last node (traversed and then) popped from the stack. When the last popped node is the last child of current node, it means that all children has already been traversed and we can now traverse current node.\n\n```\nclass Solution {\npublic:\n    vector<int> postorder(Node* root) {\n        vector<int> res;\n        if(root==nullptr) return res;\n        \n        stack<Node*> s;\n        Node* last = nullptr;\n        s.push(root);\n        while(!s.empty()){\n            Node* cur = s.top();\n            auto& children = cur->children;\n            if(!children.empty()&&last!=children.back())\n                for(int i=children.size()-1;i>=0;--i)\n                    s.push(children[i]);\n            else{\n                res.push_back(cur->val);\n                last = cur; s.pop();\n            }\n        }\n        \n        return res;\n    }\n};\n```
['C', 'Iterator', 'C++']