Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Node{
- public:
- int data;
- Node *left,*right;
- Node(int key){
- data=key;
- left=NULL;
- right=NULL;
- }
- };
- int CheckMirror(Node *root1,Node *root2){
- if(root1==NULL && root2==NULL)
- return 1;
- if(root1==NULL || root2==NULL)
- return 0;
- return root1->data==root2->data && CheckMirror(root1->left,root2->right) && CheckMirror(root1->right,root2->left);
- }
- int main(){
- Node *root1=NULL;
- Node *newnode=new Node(1);
- root1=newnode;
- root1->left=new Node(2);
- root1->right=new Node(3);
- (root1->left)->left=new Node(4);
- (root1->right)->right=new Node(5);
- Node *root2=NULL;
- Node *node=new Node(1);
- root2=node;
- root2->left=new Node(3);
- root2->right=new Node(2);
- (root2->left)->left=new Node(5);
- (root2->right)->right=new Node(4);
- if(CheckMirror(root1,root2))
- cout<<"structures are mirror of each other ";
- else
- cout<<" structures are not mirror of each other ";
- return 0;
- }
Add Comment
Please, Sign In to add comment