摘要: 一、层次化遍历说明 层次化遍历:abcdefghij 二、层次化遍历代码 思想:采用队列先进先出的特性来实现 public static void levelTraversal(TreeNode root) { if (root == null) { return; } Queue<TreeNode 阅读全文
posted @ 2021-09-11 23:36 xuan_wu 阅读(56) 评论(0) 推荐(0) 编辑
摘要: 一、递归后序遍历 public static void postOrder(TreeNode root) { if (root == null) { return; } postOrder(root.getLeft()); postOrder(root.getRight()); System.out 阅读全文
posted @ 2021-09-11 23:19 xuan_wu 阅读(386) 评论(0) 推荐(0) 编辑
摘要: 中序遍历:左子树,根节点,右子树。 一、递归中序遍历 public static void inOrder(TreeNode root) { if (root == null) { return; } inOrder(root.getLeft()); System.out.println(root. 阅读全文
posted @ 2021-09-11 23:07 xuan_wu 阅读(400) 评论(0) 推荐(0) 编辑
摘要: 先序遍历:根节点,左节点,右节点。 一、递归先序遍历 递归方式比较直接明了。 public static void preOrder(TreeNode root) { if (root == null) { return; } System.out.println(root.getValue()); 阅读全文
posted @ 2021-09-11 22:45 xuan_wu 阅读(385) 评论(0) 推荐(0) 编辑
摘要: 一、数组和二叉树的关系 二叉树可以通过数组来进行存储。https://www.cnblogs.com/Brake/p/15058906.html 数组从0开始,如果父节点在数组中的下标是i,那么其左二子在数组中对应的下标则为2i+1。右儿子子对应的下标为2i+2。 同理,已知某节点在数组中对应的下标 阅读全文
posted @ 2021-09-11 22:34 xuan_wu 阅读(1467) 评论(0) 推荐(0) 编辑