[关闭]
@ironny 2015-11-12T02:28:48.000000Z 字数 556 阅读 300

layout: post
category : 算法
title : shell 排序
tagline:

[algorithm]

{% include JB/setup %}

希尔排序

  1. public void shellSort2(int[] list) {
  2. int gap = list.length / 2;
  3. while (gap >= 1) {
  4. //插入排序
  5. for (int i = gap; i < list.length; i++) {
  6. for (int j = i - gap; j >= 0 && list[j + gap] < list[j]; j = j
  7. - gap) {
  8. int temp = list[j];
  9. list[j] = list[j + gap];
  10. list[j + gap] = temp;
  11. }
  12. }
  13. System.out.format("gap=%d:\t", gap);
  14. for (int v : list) {
  15. System.out.print(v + "\t");
  16. }
  17. System.out.println();
  18. gap = gap / 2;
  19. }
  20. }

插入排序

  1. public static void insertSort(int a[]) {
  2. int i, j;
  3. int[] b;
  4. for (i = 1; i < a.length; i++) {
  5. for (j = i - 1; j >= 0 && a[j] > a[j + 1]; j--) {
  6. int temp = a[j];
  7. a[j] = a[j + 1];
  8. a[j + 1] = temp;
  9. }
  10. }
  11. return b = a;
  12. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注