相关代码 |
|
package ShellSort; public class ShellSort { public static void print(int[] a){ for(int i=0;i System.out.print(a[i]+" "); System.out.println(); } public static void main(String args[]){ int a[]=new int[10]; for(int i=0;i a[i]=(int)(Math.random()*10); } print(a); int n=a.length; int incr=n/2; while(incr>=1){ for(i=incr;i int temp=a[i]; int j=i; while(j>=incr && temp a[j]=a[j-incr]; j-=incr; } a[j]=temp; } incr/=2; } print(a); } }