![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
程序员阿蛮
阿蛮博客
展开
-
基数排序算法
动图: 代码: public class RadixSort { public static void main(String[] args){ int[] nums = new int[]{ 8, 9, 1, 7, 2, 3, 5, 4, 6, 0 }; int[] res = sort(nums); for(int i=0; i<res.length; i++){ System.out.print(res[i] +原创 2021-07-20 17:17:46 · 58 阅读 · 0 评论 -
归并排序算法
归并排序的核心:先拆解,直到拆成1个或2个数排序,再依次将有序序列合并。 动图: 代码: public class MergeSort { public static void main(String[] args){ int[] nums = new int[]{ 8, 9, 1, 7, 2, 3, 5, 4, 6, 0 }; int[] res = sort(nums, 0, nums.length-1); for(int i=0; i<原创 2021-07-20 16:13:10 · 63 阅读 · 0 评论 -
快速排序算法
快排的核心在于:每次找到一个基准值的下标,并分别对基准值的两边进行快排。 动图: 代码: public class QuickSort { public static void main(String[] args){ int[] nums = new int[]{ 8, 9, 1, 7, 2, 3, 5, 4, 6, 0 }; int[] res = sort(nums, 0, nums.length-1); for(int i=0; i<原创 2021-07-20 14:59:21 · 62 阅读 · 0 评论 -
希尔排序算法
希尔排序是插入排序的升级版,为了防止出现较小的数聚集在后面而导致移动次数非常多的情况,采用分组进行插入排序。在数据量大的情况下,效果非常明显。 动图: 代码: public class ShellSort { public static void main(String[] args){ int[] nums = new int[]{ 8, 9, 1, 7, 2, 3, 5, 4, 6, 0 }; int[] res = sort(nums); f原创 2021-07-20 10:11:15 · 67 阅读 · 0 评论 -
插入排序算法
动图: 插入排序的关键是,总是认为前面的是有序的,所以从第二个开始比较。需要额外的一个空间来存放即将插入的值,所以当前面的元素需要后移时不用考虑覆盖问题。 代码: public static void main(String[] args){ int[] nums = new int[]{1,4,5,3,2}; int[] res = sort(nums); for(int i=0; i<res.length; i++){原创 2021-07-10 15:10:26 · 63 阅读 · 0 评论 -
选择排序算法
核心在于,每一次内层遍历都将最小的数挑出来放在序列的最前面。 每一次都是选的最小数,所以称为选择排序。 public class SelectSort { public static void main(String[] args){ int[] nums = new int[]{1,4,5,3,2}; int[] res = sort(nums); for(int i=0; i<res.length; i++){ Sy原创 2021-07-10 14:22:25 · 57 阅读 · 0 评论 -
冒泡排序算法
public class BubbleSort { public static void main(String[] args){ int[] nums = new int[]{1,4,5,3,2}; int[] res = sort(nums); for(int i=0; i<res.length; i++){ System.out.print(res[i] + " "); } }原创 2021-07-10 14:17:01 · 68 阅读 · 0 评论