# 是否包含在另一個二叉樹中的二叉樹 - C.

int sameTree(struct node *a, struct node *b){
//both empty = TRUE
if(a == NULL && b == NULL)
return TRUE;
//both not empty, compare them
else if(a != NULL && b != NULL){
return(
a->data == b->data &&
sameTree(a->left, b->left) &&
sameTree(a->right, b->right)
);
}
//one empty, one not = FALSE
else
return FALSE;


}

## 最佳答案

int in(struct node* outer, struct node* inner){
if(inner == null){
return true;//say every tree contains the empty tree
} else if(outer == null){
return false;
} else if(same(outer, inner)){
return true;
} else return in(outer->left, inner) || in(outer->right, inner);
}


int same(struct node* outer, struct node* inner){
return !inner || outer && outer->data == inner->data && same(outer->left, inner->left) && same(outer->right, inner->right);
}


int same(struct node* outer, struct node* inner){
if(inner == null){
return true;
} else if(outer == null){
return false;
} else if(outer->data == inner->data){
return same(outer->left, inner->left) && same(outer->right, inner->right);
} else return false;
}