剑指Offer-19
来源:互联网 发布:展览软件免费下载 编辑:程序博客网 时间:2024/06/05 03:36
题目:
完成一个函数,输入一个二叉树,输出它的镜像。
实现
//coding = javapublic class Solution19 { public void mirrorTree(BinaryTreeNode root){ if(root==null){ return; } BinaryTreeNode tmp = root.left; root.left = root.right; root.right = tmp; // 对结点的左右两个子树进行处理 mirrorTree(root.left); mirrorTree(root.right); } public void printTree(BinaryTreeNode root){ if(root==null){ return; } System.out.print(root.value); printTree(root.left); printTree(root.right); } public static void main(String[] args) { BinaryTreeNode root = new BinaryTreeNode(); root.value = 8; root.left = new BinaryTreeNode(); root.left.value=7; root.right = new BinaryTreeNode(); root.right.value = 6; root.left.left = new BinaryTreeNode(); root.left.left.value =5; root.left.right = new BinaryTreeNode(); root.left.right.value=4; root.right.left = new BinaryTreeNode(); root.right.left.value=3; Solution19 s19 = new Solution19(); s19.printTree(root); System.out.println(); System.out.println("镜像"); s19.mirrorTree(root); s19.printTree(root); }}
阅读全文
0 0
- 剑指Offer-19
- 剑指offer题19
- 剑指offer面试题19
- 【面试题】剑指offer 19
- 剑指Offer 19 : 二叉树镜像
- 剑指OFFER
- 剑指offer
- 剑指Offer
- 剑指offer
- 剑指Offer
- 剑指offer
- 剑指offer
- 剑指offer
- 剑指Offer
- 剑指offer
- 剑指offer
- 剑指Offer
- 剑指offer
- QT 信号与槽
- 寒假作业.java
- HBase中的备份和故障恢复方法
- Java ——面向对象的继承
- IO流学习总结
- 剑指Offer-19
- bash之通配符
- SQL note4
- php 设计模式之观察者模式
- 剪格子.java
- 安装 scikit-learn
- InputStreamReader和BufferedReader用法
- 剪邮票.java
- vue新建项目(三)构建单页应用(SPA)