hi. is it possible to write an iterative version of the post-order and in-order binary tree traversal algorithms? I know how to do the one for preorder using stacks, but I can't get my head around the other two.
please help
friend,
Name:
Anonymous2011-06-18 1:25
no. probably doomed for IT aka geek squad. it's obvious from the function name what the order is.
preorder is
int traverse(treeNode *curr) {
if (curr != NULL) {
printf("%d", curr->item);
traverse(curr->left);
traverse(curr->right);
}
}
and postorder is moving the curr->item instruction after the recursive calls. simple.