How to perform boundry 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);
}
}
Aucun commentaire:
Enregistrer un commentaire