希尔排序
package my0410; import java.util.Arrays; public class ShellSort { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int data[]={3,2,4,1,5,1,2}; sort(data); for(int i=0;i<data.length;i++){ System.out.println(data[i]); } } public static void sort(int[] data){ for(int i=data.length/2;i>2;i/=2){ for(int j=0;j<i;j++){ insertSort(data,j,i); } } insertSort(data,0,1); } public static void insertSort(int [] data,int start,int inc){ for(int i=start+inc;i<data.length;i+=inc){ for(int j=i;(j>=inc)&&(data[j]<data[j-inc]);j-=inc){ swap(data,j,j-inc); } } } public static void swap(int []data,int a,int b){ data[a]=data[a]^data[b]; data[b]=data[a]^data[b]; data[a]=data[a]^data[b]; } }