mirror_tree that accepts a pointer to the root of a binary tree of integers. Your function should rearrange the nodes into a mirror tree of the original tree. The mirror tree has the left and right subtrees reversed for each node. code example

Example: mirror a binary tree

//mirror a binary tree 

void mirror(Node root){
Queue<Node> q=new LinkedList<>();
q.add(root);
while(!q.isEmpty()){
Node currnode=q.poll();
Node temp=currnode.left;
currnode.left=currnode.right;
currnode.right=temp;
if(currnode.left!=null){
q.add(currnode.left);
}
if(currnode.right!=null){
q.add(currnode.right);
}
}
}

Tags:

Misc Example