希尔排序(缩小增量排序)

一、概念

先将整个待排序记录序列分割成若干个子序列,在子序列内分别进行直接插入排序,待整个序列基本有序时,再对全体记录进行一次直接插入排序。

二、复杂度

排序方法 最差时间分析 最好时间分析 平均时间复杂度 空间复杂度 稳定性
希尔排序 O(n2) O(n) O(n1.3) O(1) 不稳定

三、代码实现

 1 public class ShellSort {
 2     int count = 1;
 3     public void shellSort(int[] array){
 4         int j = 0;
 5         int temp = 0;
 6         for(int increment = array.length/2; increment > 0; increment /= 2){
 7             for(int i = increment; i < array.length; i++){
 8                 temp = array[i];
 9                 for(j = i - increment; j >= 0; j-= increment ){
10                     if(temp < array[j]){
11                         array[j + increment] = array[j];
12                     }else{
13                         break;
14                     }
15                 }
16                 array[j+increment] = temp;
17             }
18             printArray(array,count++);
19         }
20     }
21     public void printArray(int a[],int count){
22         if(count != 0)
23         System.out.print("第" + count + "次   ");
24         for(int m = 0; m < a.length; m++){
25             System.out.print(a[m] + " ");
26         }
27         System.out.println();
28     }
29     public static void main(String[] args) {
30         int a[] = {11,7,6,1,8,4,3,2};
31         ShellSort bs = new ShellSort();
32         bs.shellSort(a);
33     }
34 }

冒泡排序

快速排序

选择排序

堆排序

插入排序

归并排序-递归实现

基数排序

原文地址:https://www.cnblogs.com/fankongkong/p/7270131.html