/* Given two trees, should return true if they are mirror of each other. */ int areMirror(Node* a, Node* b) { if(!a && !b) return 1; if(!a || !b) return 0; if(a->data == b->data && areMirror(a->left, b->right) && areMirror(a->right, b->left)) return 1; return 0; }
int areMirror(struct Node* a, struct Node* b) { if (a == NULL && b == NULL) return 1; if (a == NULL || b == NULL) return NULL; return (a->data == b->data) && areMirror(a->left, b->right) && areMirror(a->right, b->left); }
int main() { Node *a = newNode(1); Node *b = newNode(1); a->left = newNode(2); a->right = newNode(3); a->left->left = newNode(4); a->left->right = newNode(5); b->left = newNode(3); b->right = newNode(2); b->right->left = newNode(5); b->right->right = newNode(4); areMirror(a, b)? printf("Yes") : printf("No"); return 0; }