数据结构与算法
pengge2013
这个作者很懒,什么都没留下…
展开
-
Java实现二分查找
Java实现二分查找原创 2022-10-08 16:53:06 · 202 阅读 · 0 评论 -
反转单链表
public class ReverseNode { public static void main(String[] args) { //构造链表 Node head = new Node(0); Node node1 = new Node(1); Node node2 = new Node(2); Node node3 = new Node(3); Node node4 = new Node(4);.原创 2021-01-05 21:03:59 · 72 阅读 · 0 评论 -
堆排序
基本概念:一,完全二叉树:①深度为N的完全二叉树,从作为第一层的根节点开始,处最后一层外,第N层的元素个数都必须是2的N-1次方;②最后一行的元素,都要紧贴在左边。换句话说,每一行的元素都要从最左边开始安放,两个元素之间不能有空闲。完全二叉树的性质:最后一个非叶结点是第n/2个结点。n为完全二叉树的节点总数。当前节点为i,则左叶子节点为2*i+1;右叶子节点为2*i+2。二,堆我们假设有这样一颗完全二叉树,在满足最为完全二叉树的基础上,对于任意一个拥有父节点的子节点,其数值均不小原创 2021-01-05 20:59:21 · 80 阅读 · 0 评论 -
希尔排序
import java.util.Arrays;/** * 希尔排序: * 先将序列分成较多个子序列分别进行排序,再分成较少个子序列分别进行排序,直到最后为一个序列排序。 */public class ShellSort { public static void main(String[] args) { int[] arr = {49, 38, 65, 97, 76, 13, 27, 50}; shellSort(arr); Syste.原创 2021-01-05 20:57:39 · 62 阅读 · 0 评论 -
简单插入排序
/** * 插入排序--简单插入排序 */public class InsertSort { public static void main(String[] args) { int[] arr = {12, 15, 9, 20, 6, 31, 24}; insertSort(arr); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i].原创 2021-01-05 20:56:28 · 58 阅读 · 0 评论 -
简单选择排序
一、基本思想:①从所给数组中选择最小的值,如果该位置不是该趟遍历中的起始值,则交换位置。②在剩下的数组中继续重复①。二、代码实现:import java.util.Arrays;/** * 选择排序--简单选择排序 */public class SelectionSort { public static void main(String[] args) { int[] arr = {10, 7, 2, 4, 7, 62, 3, 4, 2, 1, 8, 9,原创 2021-01-05 20:55:31 · 89 阅读 · 0 评论 -
归并排序
/** * 归并排序 */public class MergeSort { public static void main(String[] args) { int[] a = {49, 38, 65, 97, 76, 13, 27, 50}; mergeSort(a, 0, a.length - 1); System.out.println("排好序的数组:"); for (int e : a) System.out.prin.原创 2021-01-05 20:53:31 · 53 阅读 · 0 评论 -
Java实现快速排序
import java.util.Arrays;/** * 快排 */public class QuickSort { public static void main(String[] args) { int[] arr = {10, 7, 2, 4, 7, 62, 3, 4, 2, 1, 8, 9, 19}; quickSort(arr, 0, arr.length - 1); System.out.println(Arrays.toSt.原创 2021-01-05 20:52:05 · 66 阅读 · 0 评论