Write a code which will traverse the tree in post-order fashion, iteratively.
SOLUTION
void traverse( tree *root){
Stack
while ( !st.empty() && root != NULL){
while( root){
st.push(root);
root = root->left;
}
if ( st.top() ){
st.push(NULL);
root=root->right;
}
else{
st.pop();
print st.top()->data;
st.pop();
root = NULL;
}
}
}
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment