JIGYASA

An online placement forum.


You are not connected. Please login or register

Compare 2 binary trees.

Go down  Message [Page 1 of 1]

1 Compare 2 binary trees. on Sun Sep 12, 2010 6:40 am

Lucifer


Admin
Given 2 binary trees, write a function to check whether they are same or not.

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

2 Re: Compare 2 binary trees. on Tue Sep 21, 2010 5:56 am

struct node
{
int data;
struct node * left;
struct node * right;
};

// Initial value of 'same' is TRUE

void compare(node *T1 , node *T2, bool *same)
{

if (*same == TRUE)
{
if (T1 && T2 && (T1->data == T2->data))
{
compare(T1->left, T2->left, same);
compare(T1->right, T2->right, same);
}
else if(T1 || T2)
*same = FALSE;
}

}

View user profile

Back to top  Message [Page 1 of 1]

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