随笔分类 - 排序算法专题Java
摘要:import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; class My { public void bucketSort(double[] a
阅读全文
摘要: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
阅读全文
摘要: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) {
阅读全文
摘要: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 <
阅读全文
摘要: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
阅读全文
摘要: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];
阅读全文
摘要: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;//定义一个指向最小值的下标
阅读全文
摘要: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
阅读全文
摘要: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; }
阅读全文
摘要: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
阅读全文
摘要:import java.util.Arrays; public class My { public void heapSort(int[] arr) { // 前提:根节点为0号结点,结点总数为n // 若当前结点为i,则其左孩子为2*i+1,右孩子为2*i+2 // 最后一个非叶子结点为n/2-1
阅读全文

浙公网安备 33010602011771号