JIGYASA

An online placement forum.


You are not connected. Please login or register

Mirroring a binary tree.

Go down  Message [Page 1 of 1]

1 Mirroring a binary tree. on Sun Sep 12, 2010 6:27 am

Lucifer


Admin
Write a function which takes a binary tree and returns a mirror image of the same.

For ex-
Code:

  Input              Output

    1                  1
  2  3              3    2

View user profile http://jigyasa.forumn.org

2 Re: Mirroring a binary tree. on Tue Sep 21, 2010 5:41 am

struct node
{
int data;
struct node * lChild;
struct node * rChild;
};


void mirror (node *root)
{
if (root)
{
node *temp = NULL;
// Swap the children..
temp = root->rChild;
root->rChild = root->lChild;
root->lChild = temp;

// Mirror the children..
mirror(root->lChild);
mirror(root->rChild);
}
}

View user profile

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum