剑指offer系列-T24_1二叉树后序排序递归实现
来源:互联网 发布:百度网络存在安全隐患 编辑:程序博客网 时间:2024/06/04 19:47
本人对java语言更熟悉,所以剑指offer代码都是通过Java实现,且涉及的核心代码全部通过牛客网的测试用例检查,感谢牛客网为我检验程序提供了极大帮助!main函数是为了在自己运行程序时,运行结果更直观化。
/** * @param args * 二叉树后序排序递归实现 * 思路:后序排列顺序,左右根 */void BTPost(BinaryTreeNode root){if(root==null)System.out.println("");if(root.left==null&&root.right==null){System.out.println(root.val);}else{if(root.left!=null)BTPost(root.left);if(root.right!=null)BTPost(root.right);System.out.println(root.val);}}public static void main(String[] args) {// TODO Auto-generated method stubofferT24_1 o=new offerT24_1();BinaryTreeNode target1=new BinaryTreeNode(1);BinaryTreeNode target2=new BinaryTreeNode(2);BinaryTreeNode target3=new BinaryTreeNode(3);BinaryTreeNode target4=new BinaryTreeNode(4);BinaryTreeNode target5=new BinaryTreeNode(5);BinaryTreeNode target6=new BinaryTreeNode(6);BinaryTreeNode target7=new BinaryTreeNode(7);target1.left=target2;target1.right=target3;target2.left=target4;target2.right=target5;target3.left=target6;target3.right=target7;o.BTPost(target1);}}
0 0
- 剑指offer系列-T24_1二叉树后序排序递归实现
- 剑指Offer系列---(18)反转链表(递归与非递归实现)
- 剑指offer--快速排序递归实现,年龄排序O(N)实现,旋转数组最小值查找
- 剑指offer之求二叉树的深度(非递归的层次遍历)Java实现
- 剑指offer系列源码-重建二叉树
- 剑指Offer系列---(8)重建二叉树
- 【剑指offer系列】 重建二叉树___6
- 剑指offer系列----镜像二叉树
- 剑指offer 排序二叉树的合法性
- python实现剑指offer系列:重建二叉树
- 剑指Offer 面试题25:合并两个排序的链表(递归+非递归) Java代码实现
- 二叉堆,堆排序,STL优先队列的底层实现,剑指offer数据流中的中位数
- 【剑指offer】重建二叉树&&二叉树的递归与非递归遍历
- 二叉树的深度(剑指offer)递归
- 剑指offer--对称的二叉树(递归)
- 二叉树后序排序的非递归算法
- 剑指Offer系列---(10)快速排序
- 剑指offer 25 题 ,java 递归实现
- kubectl yaml/json参数设置
- scala操作数据库语句
- wait()、notify()和notifyAll()是 Object类 中的方法
- c#初学-多线程中lock用法的经典实例
- 最小生成树Prim算法
- 剑指offer系列-T24_1二叉树后序排序递归实现
- BZOJ3252 攻略
- apk的增量升级及其中的一些问题
- Java克隆调用super.clone()原理
- S3C2440与SDRAM分析
- 易付宝
- java图形验证码生成工具类及web页面校验验证码
- PAT 5-24 Find More Coins 背包记录路径
- Python input()