void tree_postorder_traversal_no_recursion (tree_node_type *root)
{
Element *top=NULL, *node, *tmp;
tree_node_type *current_node=root;
if (!root)
return;
/* push current_node into stack */
node=(Element *)malloc(sizeof(Element));
memset(node,0,sizeof(Element));
node->tree_node_ptr=current_node;
top=stack_push(top,node);
while(top) {
/* peek stack */
current_node=top->tree_node_ptr;
/* push current_node->left into stack if it's not visited */
if(current_node->left && !current_node->left->visited){
node=(Element *)malloc(sizeof(Element));
memset(node,0,sizeof(Element));
node->tree_node_ptr=current_node->left;
top=stack_push(top,node);
}
/* push current_node->right into stack if it's not visited */
else if (current_node->right && !current_node->right->visited){
node=(Element *)malloc(sizeof(Element));
memset(node,0,sizeof(Element));
node->tree_node_ptr=current_node->right;
top=stack_push(top,node);
}
else {
/* Visit current_node and mark it */
printf("%d ",current_node->object->data);
current_node->visited=TRUE;
/* pop out one and discard it */
top=stack_pop(top,&tmp);
if(tmp){
free(tmp);
}
else /* stack is empty now */
break;
} /* else */
} /* while */
}