import java.util.Scanner;
public class 希尔排序 {
public static void xierpaixu(int[] array){
int n=array.length;
int d=n/2;
while(d>=1){
for(int m=0;m<d;m++)
for(int i=m+d;i<n;i+=d){
if(array[i]<array[i-d]){
int temp=array[i];
int p=i-d;
while(p>=0&&array[p]>temp){
array[p+d]=array[p];
p-=d;
}
array[p+d]=temp;
}}
d=d/2;
}System.out.println("排序后的数组为:");
for(int i=0;i<n;i++){
System.out.print(array[i]+" ");}
}
public static void main(String[] args){
Scanner s=new Scanner(System.in);
System.out.println("请用户输入待排数组的长度:");
int n=s.nextInt();
System.out.println("请用户输入待排序的数组:");
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}System.out.println("用户输入的数组为:");
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
System.out.println();
xierpaixu(a);}
}