post order iterative help
I have been struggling with implementing a post order iterative traversal of a binary tree. One of the exercises from preludes post. I wracked my brain trying to do it without implementing this state structure, but am having problems debugging having given in to it's use. Here is the code
Code:
void post_order_traverse_iterative(tree_node* root, fptraction action)
{
struct state_node{
tree_node * header;
BOOL state;
state_node(tree_node * hd, BOOL st):header(hd), state(st){};
};
state_node* temp_state_node=new state_node{0,FALSE};
struct state_node *save[50];
int top = 0;
while (root != NULL){
save[top++]=new state_node(root,FALSE);
root=root->left;
}
temp_state_node=save[--top];// first error here type mismatch?
if (!(temp_state_node->state)){
temp_state_node->state=TRUE;
save[top++]=temp_state_node;
}
else{
temp_state_node=save[--top];
action(temp_state_node.header);
delete temp_state_node;
}
}
I am getting a number of errors, some help getting past the first one would be great. I don't know if the logic is sound but need to fix the syntax error to test it.
Here are the errors
binarytree.cc:79: error: invalid conversion from `state_node*' to `int'
binarytree.cc:81: error: syntax error before `if'
binarytree.cc:83: error: ISO C++ forbids declaration of `save' with no type
binarytree.cc:83: error: variable-size type declared outside of any function
binarytree.cc:83: error: conflicting types for `int save[2]'
binarytree.cc:70: error: previous declaration as `state_node*save[50]'
binarytree.cc:84: error: syntax error before `}' token
binarytree.cc:87: error: request for member `header' in `temp_state_node',
which is of non-class type `int'
binarytree.cc:87: error: ISO C++ forbids declaration of `action' with no type
binarytree.cc:88: error: syntax error before `delete'