예제 #1
0
int same_tree(bst *a, bst *b)
{
	if(!a && !b)
		return 1;
	if( (a&&!b) || (!a&&b))
		return 0;
	if( a->val == b->val && same_tree(a->left,a->left) && same_tree(a->right,b->right))
		return 1;
	return 0;
}
예제 #2
0
int same_tree(struct node* ptreea, struct node* ptreeb)
{
	int result = empty_case(ptreea, ptreeb);
	/* checks the empty tree case */
	if (result == TRUE || result == FALSE)
		return result;
	/* result continue: check root data and then subtrees */
	if (ptreea->data != ptreeb->data)
		return FALSE;
	if (same_tree(ptreea->left, ptreeb->left) &&
			same_tree(ptreea->right, ptreeb->right))
			return TRUE;
	return FALSE;
}
예제 #3
0
파일: tree.c 프로젝트: nabeken/bird
/**
 * same_tree
 * @t1: first tree to be compared
 * @t2: second one
 *
 * Compares two trees and returns 1 if they are same
 */
int
same_tree(struct f_tree *t1, struct f_tree *t2)
{
    if ((!!t1) != (!!t2))
        return 0;
    if (!t1)
        return 1;
    if (val_compare(t1->from, t2->from))
        return 0;
    if (val_compare(t1->to, t2->to))
        return 0;
    if (!same_tree(t1->left, t2->left))
        return 0;
    if (!same_tree(t1->right, t2->right))
        return 0;
    if (!i_same(t1->data, t2->data))
        return 0;
    return 1;
}
예제 #4
0
int main()
{
	struct node* ptreea = build_bstree();
	struct node* ptreeb = build_bstree();
	print_tree(ptreea, in_order);
	print_tree(ptreeb, post_order);
	if(same_tree(ptreea, ptreeb))
		printf("Trees are identical!\n");
	else
		printf("Trees are NOT identical!\n");
	return 0;
}