Topic
1 reply Latest Post - ‏2007-10-04T10:32:40Z by SystemAdmin
SystemAdmin
SystemAdmin
13 Posts
ACCEPTED ANSWER

Pinned topic mirroring binary tree

‏2007-09-07T09:08:32Z |
Hi,

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.
Indranil.
Updated on 2007-10-04T10:32:40Z at 2007-10-04T10:32:40Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    13 Posts
    ACCEPTED ANSWER

    Re: mirroring binary tree

    ‏2007-10-04T10:32:40Z  in response to SystemAdmin
    Node* 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);
    }
    return Target;
    }