Title: Complete a function, a binary input, the output of its mirror function
As shown in FIG: binary tree on the right is the mirror image of the left
Said step of seeking the mirror tree are as follows: We have previously preorder traversal of this tree for each node, if the node traversed node has children, exchanged its two child nodes. After completion of exchange all non-leaf nodes left child node, the mirror tree is obtained.
public void MirrorRecursively(BinaryTreeNode node){
if(node == null)
return;
if(node.leftNode == null && node.rightNode == null)
return;
BinaryTreeNode temp = node.leftNode;
node.leftNode = node.rightNode;
node.rightNode = temp;
if(node.leftNode != null)
MirrorRecursively(node.leftNode);
if(node.rightNode != null)
MirrorRecursively(node.rightNode);
}