//
// main.cpp
// Mirror Images Recursive
//
// Created by Himanshu on 04/09/21.
//
#include <iostream>
#include <queue>
using namespace std;
const int N = 5;
struct node {
int info = 0;
struct node *left, *right;
};
typedef struct node Node;
node* newNode(int data)
{
node* Node = new node();
Node->info = data;
Node->left = NULL;
Node->right = NULL;
return(Node);
}
bool checkMirrorImages (Node *root1, Node *root2) {
if (root1 == NULL && root2 == NULL) {
return true;
} else if (root1 == NULL || root2 == NULL) {
return false;
}
if (root1->info == root2->info && checkMirrorImages(root1->left, root2->right)
&& checkMirrorImages(root1->right, root2->left)) {
return true;
} else {
return false;
}
}
int main() {
Node *root1 = newNode(1);
root1->left = newNode(20);
root1->right = newNode(21);
root1->right->left = newNode(30);
root1->right->right = newNode(31);
Node *root2 = newNode(1);
root2->left = newNode(21);
root2->right = newNode(20);
root2->left->left = newNode(30);
root2->left->right = newNode(31);
if (checkMirrorImages(root1, root2)) {
cout<<"Trees are mirror Images"<<endl;
} else {
cout<<"Trees are not mirror Images"<<endl;
}
return 0;
}