sorting algorithm
  • Introduction
  • Wikipedia-sorting-algorithm
  • sorting algorithm
  • 历史 History
  • 分类 Classification
    • 稳定性 Stability
  • 算法比较 Comparison of algorithms
  • 流行排序算法 Popular sorting algorithms
    • 简单排序 Simple sorts
      • 插入排序 Insertion sort
      • 选择排序 Selection sort
    • 高效排序 Efficient sorts
      • 合并排序 Merge sort
      • 堆排序 Heapsort
      • 快速排序 Quicksort
    • 冒泡排序与变种 Bubble sort and variants
      • 冒泡排序 Bubble sort
      • 希尔排序 Shellsort
      • 梳排序 Comb sort
    • 分发排序 Distribution sort
      • 计数排序 Counting sort
      • 桶排序 Bucket sort
      • 基数排序 Radix sort
  • 内存使用模式和索引排序 Memory usage patterns and index sorting
  • 相关算法 Related algorithms
  • 另见 See also
  • 参考文献 References
  • 进一步阅读 Further reading
  • 外部链接 External links
Powered by GitBook
On this page
  • Shell sort希尔排序
  • principle原理
  • example示例

Was this helpful?

  1. 流行排序算法 Popular sorting algorithms
  2. 冒泡排序与变种 Bubble sort and variants

希尔排序 Shellsort

Previous冒泡排序 Bubble sortNext梳排序 Comb sort

Last updated 5 years ago

Was this helpful?

Shell sort希尔排序

@See @See - ShellSort

principle原理

希尔排序是按照不同步长对元素进行插入排序.

example示例

public void sort(int[] list) {
        //希尔排序
        int d = list.length;
        while (true) {
            d = d / 2;
            for (int x = 0; x < d; x++) {
                for (int i = x + d; i < list.length; i = i + d) {
                    int temp = list[i];
                    int j;
                    for (j = i - d; j >= 0 && list[j] > temp; j = j - d) {
                        list[j + d] = list[j];
                    }
//                    if (i == j + d) break;
                    list[j + d] = temp;
//                    log("swap(" + i + "," + (j + d) + ")");
                }
            }
            if (d == 1) {
                break;
            }
        }
    }
https://en.wikipedia.org/wiki/Shellsort
https://github.com/jiek2529/java_algorithm