package com.sksort;
public class insert_shell {
public static void main(String[] args) {
int a[] = {4,3,1,7,3,9,0};
insert_shell s = new insert_shell();
s.sort(a);
s.show(a);
}
public void sort(int a[]) {
int gap = a.length/2;
int temp;
while(gap>0){
for(int i=gap;i<a.length;++i){
temp = a[i];
int j = i-gap;
while(j>=0 && a[j]>temp){
a[j+gap] = a[j];
j = j-gap;
}
a[j+gap] = temp;
}
gap = gap/2;
}
}
public void show(int a[]) {
for (int i = 0; i < a.length; i++) {
if (i == 0)
System.out.print(a[i]);
else
System.out.print(" " + a[i]);
}
System.out.println();
}
}
插入类-----希尔排序
最新推荐文章于 2023-11-28 16:53:17 发布