Solved

# Iterative function

Posted on 1997-11-07

I am trying to figure out an exercise out that tries to take a copy

function(below) and make it into an iterative function of postorder traversal

that does not have any recursion. I think using a stack is appropriate

isn't it? Any ideas?

typedef struct node *tree_pointer;

typedef struct node

{

int data;

tree_pointer left_child, right child;

};

tree_pointer copy (tree_pointer original)

/*this function returns a tree_pointer to an exact copy of the original

tree*/

{

tree_pointer temp;

if(original)

{

temp=(tree_pointer)malloc(sizeof(node));

if (IS_FULL(temp)) /*IS_FULL is a macro*/

{ fprintf(stderr, "the memory is full\n");

exit(1);

}

temp->left_child = copy(original->left_child);

temp->right_child=copy(original->right_child);

temp->data=original->data;

return temp

}

return NULL;

}