I am trying to implement postorder traversal of tree using 2 stacks using iterative method. I have implementated the right algorithm. But still didn't getting output, getting error as, Segmentation fault (core dumped). Where I have done wrong can anyone tell me ?
void postorder_iterative(struct node *root)
{
struct node *stack1[15],*stack2[15];
int top1=-1,top2 =-1;
root = stack1[++top1];
while(top1>=0)
{
root = stack1[top1--];
stack2[++top2] =root;
if(root->left != NULL)
stack1[++top1] = root->left;
if(root->right != NULL)
stack1[++top1] = root->right;
}
while(top2>=0)
printf("%c\t",stack2[top2--]->data);
}