面试题二十七:二叉树的镜像二叉树

左右子树颠倒

  1. 前序遍历
    1.   在遍历过程中将左右节点颠倒后在遍历左右子树
void f1( BinaryTreeNode A){

            if( A==null ) return ;
            if( A.L==null && A.R==null ) return ;   //叶子

            BinaryTreeNode temp= A.L;
            A.L=A.R;
            A.R=temp;  //左右交换

            if( A.L !=nullreturn f1( A.L);
            if( A.R !=null )   return  f1( A.R);

    }

 

posted @ 2020-03-29 14:49  浪波激泥  阅读(149)  评论(0编辑  收藏  举报