package org.charu;
public class ShellSort {
public static void main(String[] args) {
int a[] = {65,34,25,87,12,38,56,46,14,77,92,23};
int d[] = {6,3,1};
System.out.print("排序之前:");
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
sort(a,d);
System.out.print("\n排序之后:");
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
}
public static void sort(int a[],int d[]){
int temp,span,j;
for(int m = 0;m<d.length;m++){
span = d[m];
for(int k = 0;k<span;k++){
for(int i = 0;i<a.length-span;i = i+span){
temp = a[i+span];
j = i;
while(j>-1&&temp<a[j]){
a[j+span] = a[j];
j--;
}
a[j+1] = temp;
}
}
}
}
}
public class ShellSort {
public static void main(String[] args) {
int a[] = {65,34,25,87,12,38,56,46,14,77,92,23};
int d[] = {6,3,1};
System.out.print("排序之前:");
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
sort(a,d);
System.out.print("\n排序之后:");
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
}
public static void sort(int a[],int d[]){
int temp,span,j;
for(int m = 0;m<d.length;m++){
span = d[m];
for(int k = 0;k<span;k++){
for(int i = 0;i<a.length-span;i = i+span){
temp = a[i+span];
j = i;
while(j>-1&&temp<a[j]){
a[j+span] = a[j];
j--;
}
a[j+1] = temp;
}
}
}
}
}