希尔排序

package insert;

import java.util.Arrays;
public class ShellSort {
	public static void main(String[] args) {
		int[] A={19,10,9,8,7,6,5,4,3,2,1,0};
		System.out.println(Arrays.toString(A));
		System.out.println("-----------------------");
		int a=A.length;
		int b;
		int step,i,j;
		for(step=a/2;step>=1;step=step/2){
			for(i=step;i<a;i++){
				b=A[i];
				if(b<A[i-step]){
					for(j=i-step;j>=0&&b<A[j];j-=step){
						A[j+step]=A[j];
					}
					A[j+step]=b;
				}
			}
		}
		System.out.println(Arrays.toString(A));
	}
	
}

点赞