1 2 3 4 5 ··· 20 下一页
摘要: 一、演示 两个指针分别指向,数组a和数组b的首位置。 比较两个指针所指元素的值。 将小的值赋值给合并后的数组,并且值小的指针迁移 继续第一步。 二、代码 public class Merge { public static void main(String[] args) { int[] a = n 阅读全文
posted @ 2021-10-17 23:30 xuan_wu 阅读(65) 评论(0) 推荐(0) 编辑
摘要: 一、选择排序的弊端 需要n^2。核心的耗时在每次寻找最大值。 public static void selectionSort(int[] list) { for (int index = 0; index < list.length - 1; index++) { int minIndex = f 阅读全文
posted @ 2021-09-29 23:31 xuan_wu 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 一、最大堆建立 给定N个元素,按照最大堆的要求将元素放入数组中。 两种做法: 通过插入,依次将N个元素插入一个空堆中,复杂度为nlogn。 线性复杂度建立堆 先将N个元素按照顺序存入,先满足完全二叉树的特性 调整各个节点,让其满足最大堆的特性 本文主要介绍第二种方法,线性复杂度创建堆。 二、线性复杂 阅读全文
posted @ 2021-09-25 23:02 xuan_wu 阅读(993) 评论(0) 推荐(0) 编辑
摘要: 一、堆定义 堆是一个优先队列,右二叉树来表示,其特性: 是一颗完全二叉树 任意节点的元素是其子树的最大值(最小值) 最大值,大顶堆 最小值,小顶堆 示例: 完全二叉树用数组继续存储。定义如下: public class HeapStruct { private Integer[] elements; 阅读全文
posted @ 2021-09-23 23:09 xuan_wu 阅读(1911) 评论(0) 推荐(0) 编辑
摘要: 一、层次化遍历说明 层次化遍历: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 阅读(383) 评论(0) 推荐(0) 编辑
摘要: 一、数组和二叉树的关系 二叉树可以通过数组来进行存储。https://www.cnblogs.com/Brake/p/15058906.html 数组从0开始,如果父节点在数组中的下标是i,那么其左二子在数组中对应的下标则为2i+1。右儿子子对应的下标为2i+2。 同理,已知某节点在数组中对应的下标 阅读全文
posted @ 2021-09-11 22:34 xuan_wu 阅读(1458) 评论(0) 推荐(0) 编辑
摘要: ![](https://img2020.cnblogs.com/blog/737467/202108/737467-20210822214042895-21909559.png) 阅读全文
posted @ 2021-08-22 21:41 xuan_wu 阅读(28) 评论(0) 推荐(0) 编辑
1 2 3 4 5 ··· 20 下一页