You are viewing a single comment's thread. Return to all comments →
void postOrder(node *root) { stack<node *>s1; stack<node *>s2; vector<int>res; node * a=root; s1.push(a); while(!s1.empty()) { a=s1.top(); s2.push(a); s1.pop(); if(a->left) s1.push(a->left); if(a->right) s1.push(a->right); } while(!s2.empty()) { res.push_back(s2.top()->data); s2.pop(); } for(int i=0;i<res.size();i++) cout<<res[i]<<" "; }
Tree: Postorder Traversal
You are viewing a single comment's thread. Return to all comments →