can you give an idea on how mirroring of a binary tree can be done in a single pass ? if possible please give the snippet of the code.
Thanks & Warm Regards.
This topic has been locked.
1 reply Latest Post - 2007-10-04T10:32:40Z by SystemAdmin
Pinned topic mirroring binary tree
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2007-10-04T10:32:40Z at 2007-10-04T10:32:40Z by SystemAdmin
SystemAdmin 110000D4XK13 PostsACCEPTED ANSWER
Re: mirroring binary tree2007-10-04T10:32:40Z in response to SystemAdminNode* mirror(Node* N, Node* Target)
Node* L = N->leftchild();
Node* R = N->rightChild();
if( !L && !R )
Node* TargetL=new node();
TargetL->data = R->data;
Node* TargetR=new node();
TargetR->data = L->data;
Target->leftchild = mirror(R,TargetL);
Target->rightchild = mirror(L,TargetR);