随笔分类 -  排序算法专题Java

摘要:import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; class My { public void bucketSort(double[] a 阅读全文
posted @ 2020-08-02 23:54 执着于风 阅读(111) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { void insertSort(int[] arr) { int n=arr.length; for(int i=1;i<n;i++){ int temp=arr[i]; int j; for(j=i-1;j>=0 阅读全文
posted @ 2020-08-02 22:58 执着于风 阅读(119) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { void shellSort(int[] arr) { int n=arr.length; //当gap=1时,就是直接插入排序 for (int gap = n / 2; gap > 0; gap /= 2) { 阅读全文
posted @ 2020-08-02 22:56 执着于风 阅读(71) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { public void bubbleSort(int[] arr) { int n=arr.length; int left = 0, right = n - 1; int p = 0; while (left < 阅读全文
posted @ 2020-08-02 22:55 执着于风 阅读(189) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { void bubbleSort(int[] arr){ int n=arr.length; for(int i=0;i<n-1;i++){ boolean flag=false; for(int j=0;j<n-1 阅读全文
posted @ 2020-08-02 22:54 执着于风 阅读(84) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { void quickSort(int[] arr, int start,int end){ if(start>=end){ //必须start>=end return; } int temp=arr[start]; 阅读全文
posted @ 2020-08-02 22:53 执着于风 阅读(87) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { void selectSort(int[] arr) { int n = arr.length; for (int i = 0; i < n - 1; i++) { int p = i;//定义一个指向最小值的下标 阅读全文
posted @ 2020-08-02 22:52 执着于风 阅读(73) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { public void countSort(int[] arr) { int max = arr[0]; int min = arr[0]; for (int a : arr) { if (a > max) { m 阅读全文
posted @ 2020-08-02 22:51 执着于风 阅读(108) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { public void radixSort(int[] arr) { int max = arr[0]; //初始化最大值 for (int a : arr) { if (a > max) { max = a; } 阅读全文
posted @ 2020-08-02 22:50 执着于风 阅读(128) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { public void mergeSort(int[] arr, int low, int high) { if (low >= high) { return; } int mid = low + (high-lo 阅读全文
posted @ 2020-08-02 22:49 执着于风 阅读(101) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class My { public void heapSort(int[] arr) { // 前提:根节点为0号结点,结点总数为n // 若当前结点为i,则其左孩子为2*i+1,右孩子为2*i+2 // 最后一个非叶子结点为n/2-1 阅读全文
posted @ 2020-08-02 22:48 执着于风 阅读(112) 评论(0) 推荐(0)