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;
- }
- };
- void Inorder(Node* root){
- if(root==NULL)
- return;
- Inorder(root->left);
- cout<<" "<<root->data;
- Inorder(root->right);
- }
- void Mirror(Node* root){
- if(root==NULL)
- return ;
- Node* temp=root->left;
- root->left=root->right;
- root->right=temp;
- Mirror(root->left);
- Mirror(root->right);
- }
- int main(){
- Node *root=NULL;
- Node *newnode=new Node(1);
- root=newnode;
- root->left=new Node(9);
- root->right=new Node(3);
- (root->left)->left=new Node(2);
- (root->right)->right=new Node(4);
- Inorder(root);
- Mirror(root);
- cout<<endl<<"after making mirror tree :"<<endl;
- Inorder(root);
- return 0;
- }
Add Comment
Please, Sign In to add comment