面试题二十七:二叉树的镜像二叉树
左右子树颠倒
- 前序遍历
- 在遍历过程中将左右节点颠倒后在遍历左右子树
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 !=null ) return f1( A.L); if( A.R !=null ) return f1( A.R); }
浪波激泥