Convert recursive binary tree traversal to iterative
I was asked to write the iterative version, but I wrote the recursive version i.e. void inorderTraverse(BinaryTree root) { if(root==NULL) printf("%d",root->id); else { inorderTraverse(root->left); printf("%d",root->id); inorderTraverse(root->right); } } I'm not looking for the code, I want to understand how this can be done. Had it been just the last recursive call, I would have done void inorderTraverse(BinaryTree root) { while(root!=NULL) { printf("%d",root->id); root=root->right; } } But how do I convert to an iterative program when there are two recursive calls? Here are the type