LoginSignup
0
0

More than 3 years have passed since last update.

java シェルソート

Posted at

java シェルソート

今回はシェルソートについてコードを書いていく。
※自分のアウトプット用の記事です。間違いなどがあったら指摘してください。

ShellSort.java
public class ShellSort {
    public static void sort(int[] array) {
        int h;

        for(h=1;h<array.length/9;h=h*3+1) {

        }

        for(;h>0;h/=3) {
            for(int i=h;i<array.length;i++) {
                int j=i;
                while(j>=h && array[j-h]>array[j]) {
                    int temp = array[j];
                    array[j] = array[j-h];
                    array[j-h] = temp;
                    j -= h;
                }
            }
        }
    }
    public static void main(String args[]) {
        int[] array = {3,2,4,5,1};
        sort(array);
        for(int i=0;i<array.length;i++) {
            System.out.print(array[i]);
        }
    }
}

次回はクイックソートを試してみようと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0