Prove safety offer: a binary image (java)

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);  
    }  


Published 118 original articles · won praise 35 · views 120 000 +

Guess you like

Origin blog.csdn.net/abc7845129630/article/details/52724841
Recommended