JIGYASA
Would you like to react to this message? Create an account in a few clicks or log in to continue.
JIGYASA

An online placement forum.


You are not connected. Please login or register

Compare 2 binary trees.

2 posters

Go down  Message [Page 1 of 1]

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

Lucifer


Admin

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

https://jigyasa.forumotion.com

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

codecrker



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;
}

}

Back to top  Message [Page 1 of 1]

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