JAva常用ソートアルゴリズムのヒルソート



package com.zjp.start.sort;

import java.util.Arrays;

/**
 *     :
 *                   ,               ,           。
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {49, 38, 65, 97, 76, 13, 27, 50};
        shellSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void shellSort(int[] arr) {
        //    
        int increment = arr.length / 2;
        while (increment >= 1) {
            //          
            for (int i = 0; i < increment; i++) {
                //    
                for (int j = i + increment; j < arr.length; j += increment) {//j        
                    int k = j;//k         
                    int tmp = arr[j];
                    while (k >= increment && arr[k - increment] > tmp) {
                        //    
                        arr[k] = arr[k - increment];
                        k -= increment;
                    }
                    //    
                    arr[k] = tmp;
                }
            }
            //    
            increment = increment / 2;
        }
    }
}