这里是代码,我需要为我的项目
但我不熟悉C
任何机构可以改变它的Java PLZ {S0的}
| DominoBoy
void iterativePostOrder(Node* root) {
if (!root) {
return;
}
stack<node*> nodeStack;
Node* cur = root;
while (true) {
if (cur) {
if (cur->right) {
nodeStack.push(cur->right);
}
nodeStack.push(cur);
cur = cur->left;
continue;
}
if (nodeStack.empty()) {
return;
}
cur = nodeStack.top();
nodeStack.pop();
if (cur->right && !nodeStack.empty() && cur->right == nodeStack.top()) {
nodeStack.pop();
nodeStack.push(cur);
cur = cur->right;
} else {
std::cout << cur->val << " ";
cur = NULL;
}
}
}