Mirror image of a binary tree

前端 未结 13 2497
时光取名叫无心
时光取名叫无心 2020-12-01 09:00

Suppose there is a tree:

             1
            / \\
           2   3
              / \\
             4   5

Then the mirror image will

13条回答
  •  一整个雨季
    2020-12-01 09:19

    void mirror(node *& root2,node * root)
    {
        if(root==NULL)
        {
            root2=NULL;
        }
        else {
            root2=new node;
            root2->data=root->data;
            root2->left=NULL;
            root2->right=NULL;
            mirror(root2->left,root->right);
            mirror(root2->right,root->left);
        }
    }
    

提交回复
热议问题