C++ iterative without reverse
The extra integer in the stack represents the index of the child to push.\n\nclass Solution {\npublic:\n    vector<int> postorder(Node* root) {\n        if (!ro
The extra integer in the stack represents the index of the child to push.\n```\nclass Solution {\npublic:\n    vector<int> postorder(Node* root) {\n        if (!root) {\n            return {};\n        }\n        std::stack<std::pair<Node *, int>> s;\n        std::vector<int> res;\n        s.emplace(root, 0);\n        while (!s.empty()) {\n            auto &[node, index] = s.top();\n            if (index == node->children.size()) {\n                res.push_back(node->val);\n                s.pop();\n            } else {\n                s.emplace(node->children[index++], 0);\n            }\n        }\n        return res;\n    }\n};\n```
['C', 'Iterator']