How to perform boundary traversal in binary tree using only single traversal of the tree?
I am doing it in this way (not a single traversal):
void printBoundary (struct node* root)
{
if (root)
{
printf("%d ",root->data);
// Print the left boundary in top-down manner.
if( root->left)
printBoundaryLeft(root->left);
else
printBoundaryLeft(root->right);
// Print all leaf nodes
printLeaves(root->left);
printLeaves(root->right);
// Print the right boundary in bottom-up manner
if(root->right)
printBoundaryRight(root->right);
else
printBoundaryRight(root->left);
}
}