public void Mirror(BitNode root) { if(root==null) return;; else { BitNode temp=root.lchild; root.lchild=root.rchild; root.rchild=temp; Mirror(root.lchild); Mirror(root.rchild); } } public void Mirror1(BitNode root){ if(root==null) { return;; } LinkedList<BitNode> stack =new LinkedList<BitNode>(); BitNode current=null; BitNode temp=null; stack.push(root); while (!stack.isEmpty()){ current=stack.pop(); if (current.lchild!=null||current.rchild!=null) { temp=current.lchild; current.lchild=current.rchild; current.rchild=temp; } if(current.lchild!=null) stack.push(current.lchild); if (current.rchild!=null) stack.push(current.rchild); } }
求一个二叉树的镜像 递归和非递归思想
最新推荐文章于 2021-06-04 14:58:13 发布